rails 4, active record: appending to has_many :through does not create join model anymore?

207 views
Skip to first unread message

glaszig

unread,
May 21, 2013, 9:39:54 PM5/21/13
to rubyonra...@googlegroups.com
hi folks.

on rails 4, can somebody confirm that pushing model instances onto a has_many :through relation does not create the necessary join model anymore?

    class Reader < AR::Base
      belongs_to :post
      belongs_to :person
    end

    class Post < AR::Base
      has_many :readers
      has_many :people, through: :readers
    end

    @post.people << Person.new


thanks.

Anthony Richardson

unread,
May 21, 2013, 9:47:25 PM5/21/13
to rubyonra...@googlegroups.com
You probably need to use "create" and not "new" so there is something to put in the foreign keys.


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-co...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
Visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

glaszig

unread,
May 21, 2013, 9:50:53 PM5/21/13
to rubyonra...@googlegroups.com
yech. found the culprit. my fault.
lesson learned: don't fuck around by aliasing association accessors.

sorry to bother you.

Martin Glaß

unread,
May 21, 2013, 9:53:05 PM5/21/13
to rubyonra...@googlegroups.com
anthony, just tried and it works with unsaved instances as well :)
thanks.

You received this message because you are subscribed to a topic in the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rubyonrails-core/FLt6AP-rEjY/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to rubyonrails-co...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages