I have a "Dependant destroy" and it wont work as its reference is not standard . By this I mean that I have changed the XXX_id to be something else as I had clashes: ambiguous relationships. class Product < ActiveRecord::Base belongs_to :company has_many :allocations, :dependent => :destroy has_many :companies, :through => :allocations class Company < ActiveRecord::Base has_many :products, :dependent => :destroy has_many :allocations, :dependent => :destroy has_many :allocated_products, :through => :allocations And the joining table with an extra field class Allocation < ActiveRecord::Base belongs_to :company belongs_to :allocated_product, :class_name => ''Product'' end I realize the error I get when testing deleting a company is due to the fact that its looking to delete product_id from the allocations table but cannot find it. "Mysql::Error: Unknown column ''allocations.product_id'' in ''where clause'': SELECT * FROM `allocations` WHERE (`allocations`.product_id 3)" I have looked for options on the call but cant see any suitable Can I best do this by using an after delete filter, and how? Thanks -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Maybe you need to set the :foreign_key option on your association to "some_other_id"... On Jan 26, 11:03 am, Craig Leppan <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I have a "Dependant destroy" and it wont work as its reference is not > standard .-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
shiva s
2011-Jan-26 16:49 UTC
Re: Re: Dependant destroy with altered _id name in join table
Sir, This Shiva,I''m a web designer I would like to know about the Ruby on rails and would like to learn more bout it,can you explain bout it??&need to know the advantages of this concept -- Thanks and Regards, Shiva Business Development Team, 3 DOT VENTURE shivaneswaran.3dotventure-Re5JQEeQqe9fmgfxC/sS/w@public.gmane.org Phone No:+1-7024339913 Visit us at :www.3dotventure.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 26 January 2011 16:03, Craig Leppan <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I have a "Dependant destroy" and it wont work as its reference is not > standard . By this I mean that I have changed the XXX_id to be something > else as I had clashes: ambiguous relationships. > > class Product < ActiveRecord::Base > belongs_to :company > has_many :allocations, :dependent => :destroyI think you need to specify :foreign_key => ''allocated_product_id'' on the above. Colin> has_many :companies, :through => :allocations > > class Company < ActiveRecord::Base > has_many :products, :dependent => :destroy > has_many :allocations, :dependent => :destroy > has_many :allocated_products, :through => :allocations > > And the joining table with an extra field > class Allocation < ActiveRecord::Base > belongs_to :company > belongs_to :allocated_product, :class_name => ''Product'' > end > > I realize the error I get when testing deleting a company is due to the > fact that its looking to delete product_id from the allocations table > but cannot find it. > > "Mysql::Error: Unknown column ''allocations.product_id'' in ''where > clause'': SELECT * FROM `allocations` WHERE (`allocations`.product_id > 3)" > > I have looked for options on the call but cant see any suitable > Can I best do this by using an after delete filter, and how? > > Thanks > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Craig Leppan
2011-Jan-27 08:55 UTC
Re: Dependant destroy with altered _id name in join table
Beautiful, than-you Just so people can see solution: class Company < ActiveRecord::Base has_many :memberships, :dependent => :destroy has_many :notes, :dependent => :destroy has_many :contacts, :through => :memberships has_many :products, :dependent => :destroy has_many :allocations, :dependent => :destroy, :foreign_key => ''allocated_product_id'' #, :dependent => :destroy has_many :allocated_products, :through => :allocations -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.