er_tanoso-s8PdfxpoPdHk1uMJSBkQmQ@public.gmane.org
2005-May-24 10:24 UTC
Deleting from a ''has_many'' collection doesn''t set the foreign key to NULL
Hi all, I have an Active Record problem. Having this classes declaration. class Sale < ActiveRecord::Base has_many :sale_line_items, :class_name ''SaleLineItem'' ... end class SaleLineItem < ActiveRecord::Base ... end When I try to delete an item in a Sale class method from sale_line_items (sale_line_items.delete(li)), it extracts ''li'' from the container as expected, but it doesn''t set the foreign_key ''sale_id'' to NULL as especified in the documentation. please, could someone tell me if i misunderstood something (my english is poor), or if it is a BUG???
Doug Alcorn
2005-May-24 13:02 UTC
Re: Deleting from a ''has_many'' collection doesn''t set the foreign key to NULL
er_tanoso-s8PdfxpoPdHk1uMJSBkQmQ@public.gmane.org writes:> class Sale < ActiveRecord::Base > has_many :sale_line_items, :class_name ''SaleLineItem'' > > ... > > end > > class SaleLineItem < ActiveRecord::Base > ... > > end > > When I try to delete an item in a Sale class method from sale_line_items > (sale_line_items.delete(li)), it extracts ''li'' from the container as > expected, but it doesn''t set the foreign_key ''sale_id'' to NULL as especified > in the documentation.Does SaleLineItem belongs_to :sale? AR needs to know there''s a foreign key in sale_line_items linking it to the sale. The belongs_to keyword is what sets this up. -- doug-jGAhs73c5XxeoWH0uzbU5w@public.gmane.org
er_tanoso-s8PdfxpoPdHk1uMJSBkQmQ@public.gmane.org
2005-May-26 11:29 UTC
Re: Deleting from a ''has_many'' collection doesn''t set the foreign key to NULL
er_tanoso-s8PdfxpoPdHk1uMJSBkQmQ@public.gmane.org writes:>> class Sale < ActiveRecord::Base >> has_many :sale_line_items, :class_name ''SaleLineItem'' >> >> ... >> >> end >> >> class SaleLineItem < ActiveRecord::Base >> ... >> >> end >> >> When I try to delete an item in a Sale class method from sale_line_items >> (sale_line_items.delete(li)), it extracts ''li'' from the container as >> expected, but it doesn''t set the foreign_key ''sale_id'' to NULL as >>especified in the documentation.>Does SaleLineItem belongs_to :sale? AR needs to know there''s a foreign >key in sale_line_items linking it to the sale. The belongs_to keyword >is what sets this up.>doug-jGAhs73c5XxeoWH0uzbU5w@public.gmane.orgSorry for my delay to reply, I''ve done what you say (I really thougth it was the solution), SaleLineItems belongs_to Sale now, but I get the same problem. May this be a BUG??.