I have two tables: airlinememberships and loyaltycars. The loyaltycars
table just keeps track of what car memberships people want to asscoiate
with an airlinemembership program. So that means that loyaltycars
belongs_to => :airlinemmebership which means that I have a
airlinemembership_id column in my loyatlycars table. Then in my
ailrinemebership table I have has_many :loyaltycars, :dependent =>
:destroy.
So my question is when I delete an airlinemebership from the table does
that also delete the asscoaition from the loyaltycars table based on the
fact that I have a field in that table holding the airlinemembership id
by way of that :destroy statement?
Also when looking at the documention for the models there is a :destroy
and a :destroy_all. What is the difference between the two. Thanks,
fact that I have a field in that table holding the airlinemembership id
by way of that :destroy statement?
Yes. But you must use destroy to delete the airlinemembership, not
delete.
Be careful, delete just is lower level method to delete records as it
skips any dependancy checking you may have. But it is faster if you
need to delete a lot of records quickly and you don’t care about
integrity checks.
Also when looking at the documention for the models there is a :destroy
and a :destroy_all. What is the difference between the two.
Destroy only worths with ids, and you can pass multiple id numbers to
destroy. Destroy_all can work with any condition you want, like
airlinemembership.destroy( “active = false”).
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.