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 end class ArtistEvent < ActiveRecord::Base belongs_to :artist belongs_to :event end In irb i get all events for an artist with "a.events" (where a = Artist.first). But e.artist returns 'nil'. Whats strange is that a.artist_event returns nill as well. However, when I run a 'find_by' on the artist_event table and use e.id, the artist_event is returned. I have tried changing the Event class to use has_one as opposed to belongs_to, without effect. What am I missing? Do I need to have an index in the schema? -- Posted via http://www.ruby-forum.com/. -- 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 [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/1849c51f03107ed6416f71e94e5a8f5b%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.

