glaszig
2013-May-22 01:39 UTC
rails 4, active record: appending to has_many :through does not create join model anymore?
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 so, basically this is not working: http://guides.rubyonrails.org/association_basics.html#has_many-uniq thanks. -- 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-core+unsubscribe@googlegroups.com. To post to this group, send email to rubyonrails-core@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.
Anthony Richardson
2013-May-22 01:47 UTC
Re: rails 4, active record: appending to has_many :through does not create join model anymore?
You probably need to use "create" and not "new" so there is something to put in the foreign keys. On Wed, May 22, 2013 at 11:09 AM, glaszig <glaszig@gmail.com> wrote:> 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 > > so, basically this is not working: > http://guides.rubyonrails.org/association_basics.html#has_many-uniq > > thanks. > > -- > 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-core+unsubscribe@googlegroups.com. > To post to this group, send email to rubyonrails-core@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. > > >-- 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-core+unsubscribe@googlegroups.com. To post to this group, send email to rubyonrails-core@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
2013-May-22 01:50 UTC
Re: rails 4, active record: appending to has_many :through does not create join model anymore?
yech. found the culprit. my fault. lesson learned: don''t fuck around by aliasing association accessors. sorry to bother you. Am Mittwoch, 22. Mai 2013 03:47:25 UTC+2 schrieb Richo99:> > You probably need to use "create" and not "new" so there is something to > put in the foreign keys. > > > On Wed, May 22, 2013 at 11:09 AM, glaszig <gla...@gmail.com <javascript:>>wrote: > >> 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 >> >> so, basically this is not working: >> http://guides.rubyonrails.org/association_basics.html#has_many-uniq >> >> thanks. >> >> -- >> 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 <javascript:>. >> To post to this group, send email to rubyonra...@googlegroups.com<javascript:> >> . >> Visit this group at http://groups.google.com/group/rubyonrails-core?hl=en >> . >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> > >-- 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-core+unsubscribe@googlegroups.com. To post to this group, send email to rubyonrails-core@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.
Martin Glaß
2013-May-22 01:53 UTC
Re: rails 4, active record: appending to has_many :through does not create join model anymore?
anthony, just tried and it works with unsaved instances as well :) thanks. Am 22.05.2013 um 03:47 schrieb Anthony Richardson <richo990@gmail.com>:> You probably need to use "create" and not "new" so there is something to put in the foreign keys. > > > On Wed, May 22, 2013 at 11:09 AM, glaszig <glaszig@gmail.com> wrote: > 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 > > so, basically this is not working: http://guides.rubyonrails.org/association_basics.html#has_many-uniq > > thanks. > > -- > 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-core+unsubscribe@googlegroups.com. > To post to this group, send email to rubyonrails-core@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. > > > > > -- > 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-core+unsubscribe@googlegroups.com. > To post to this group, send email to rubyonrails-core@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. > >-- 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-core+unsubscribe@googlegroups.com. To post to this group, send email to rubyonrails-core@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.