If I have two models that are in a one-to-one relationship in Ruby on
Rails,
and I wish to delete a record.
How do I make sure I will delete all the related data from both tables?
Is there a simple elegant Ruby way to do this?
Thank you for your time in advance,
Mitch
On 22 Jul 2008, at 18:43, Mitchell G. wrote:
If I have two models that are in a one-to-one relationship in Ruby on
Rails,
and I wish to delete a record.
How do I make sure I will delete all the related data from both
tables?
Is there a simple elegant Ruby way to do this?
rails provides the :dependant option.
If you want a cast iron guarantee then you need to get the database to
do it for you (foreign key)
Fred
Frederick C. wrote:
On 22 Jul 2008, at 18:43, Mitchell G. wrote:
If I have two models that are in a one-to-one relationship in Ruby on
Rails,
and I wish to delete a record.
How do I make sure I will delete all the related data from both
tables?
Is there a simple elegant Ruby way to do this?
rails provides the :dependant option.
If you want a cast iron guarantee then you need to get the database to
do it for you (foreign key)
Fred
Thanks Fred. I have a foreign key in one of the tables. Does that mean
when I delete a record in rails it will automatically delete from both
joined tables?
Mitch
On 22 Jul 2008, at 21:20, Mitchell G. wrote:
tables?
Thanks Fred. I have a foreign key in one of the tables. Does that
mean
when I delete a record in rails it will automatically delete from both
joined tables?
By default it will probably just raise an error. Check your database’s
documentation
Fred
Thanks Fred. I have a foreign key in one of the tables. Does that
mean
when I delete a record in rails it will automatically delete from both
joined tables?
By default it will probably just raise an error. Check your database’s
documentation
Would it depend on whether the belongs_to on that foreign key relation
also has :dependent => :destroy? Does the cascading destroy recurse
through multiple levels of association or does it only apply to the
root object and it’s associations?
On Jul 22, 4:21 pm, Frederick C. [email protected]
On 22 Jul 2008, at 21:38, Robert W. wrote:
Would it depend on whether the belongs_to on that foreign key relation
also has :dependent => :destroy?
No - the rails world of dependant => :destroy and the database world
are independent
Does the cascading destroy recurse
through multiple levels of association or does it only apply to the
root object and it’s associations?
Might do - try it and find out I would imagine so though.
(but :dependent => :delete_all probably doesn’t recurse)
Fred