When I was using habtm product.categories.replace(..category objects) was working fine But when I started using has_many :through other relations are working, but I am not able to do product.categories.replace(..category objects) What is the solution then? Regards, Anil Wadghule --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> What is the solution then?Can you post your relationship declarations for the product and category models? Steve --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Steve, These are relationship declarations for product, category and CategoriesProduct models! class Product < ActiveRecord::Base has_many :categories_products has_many :categories, :through => :categories_products class Category < ActiveRecord::Base has_many :categories_products has_many :products, :through => :categories_products class CategoriesProduct < ActiveRecord::Base belongs_to :category belongs_to :product end On 2/2/07, Steve Bartholomew <steve-LWB5c3/XHbdBDgjK7y7TUQ@public.gmane.org> wrote:> > > > What is the solution then? > Can you post your relationship declarations for the product and > category models? > > Steve >-- Don''t live to geek; geek to live. http://anildigital.blogspot.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Anil Wadghule wrote:> When I was using habtm > > product.categories.replace(..category objects) was working fine > > But when I started using has_many :through > > other relations are working, but I am not able to do > > product.categories.replace(..category objects) > > What is the solution then?#replace is not implemented for has_many :through associations. You can roll your own though. Just delete the join model records of old ones not in the new set, then create join model records for the new ones not in the old set. And of course you should wrap that in a transaction. -- Josh Susser http://blog.hasmanythrough.com/ -- 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 post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks Josh, I did the same. Regards, Anil Wadghule On 2/4/07, Josh Susser <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Anil Wadghule wrote: > > When I was using habtm > > > > product.categories.replace(..category objects) was working fine > > > > But when I started using has_many :through > > > > other relations are working, but I am not able to do > > > > product.categories.replace(..category objects) > > > > What is the solution then? > > #replace is not implemented for has_many :through associations. You can > roll your own though. Just delete the join model records of old ones not > in the new set, then create join model records for the new ones not in > the old set. And of course you should wrap that in a transaction. > > -- > Josh Susser > http://blog.hasmanythrough.com/ > > -- > Posted via http://www.ruby-forum.com/. > > > >-- Don''t live to geek; geek to live. http://anildigital.blogspot.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---