On 8 October 2015 at 01:46, Chris Berry <lists@ruby-forum.com> wrote:
> I have two tables in my app which I am attempting to relate through a
> join table. The Artist class which uses 'has_many through', works as
> expected. However, the Event class using 'has_one through', brings back
> nil.
>
> class Artist < ActiveRecord::Base
> has_many :artist_events, dependent: :destroy
> has_many :events, through: :artist_events
> end
>
> class Event < ActiveRecord::Base
> belongs_to :artist_event
> has_one :artist, through: :artist_events
I have not done this but I think it should be
has_one :artist_event # to match ArtistEvent belongs_to event
has_one :artist through: artist_event # note, singular artist_event
However, in this scenario I don't think you need the join table at
all, why not just have
Artist has_many events
Event belongs_to artist
Colin
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLtAACybt_Gu%2B%2BQx0bnnOmVwOoaznKAgv9hW7X4Ks_k5oQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment