Forum: Ruby on Rails ActiveRecord :dependent problem

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Aff4383ed81560b655c12a4abb9e2d94?d=identicon&s=25 Christian Weyer (ngz7)
on 2007-03-25 18:21
Hey guys,

I have trouble with the ActiveRecord dependent option, I guess it's a
bug in ActiveRecord.

I have a superclass called 'list' which has to subclasses 'hard_list'
and 'intelligent_list'. I'm working with single table inheritance and it
works well. There is a table called lists, which holds information about
my lists, a table called items, which has all the list items and a table
called lists_items, which knows what item belogs to what list.

Now the problem: my intelligent_list does not have items in that
lists_item table since its items are fetched with an user-defined SQL
query. I used :finder_sql for that and it works fine. But when I want to
delete that list, ActiveRecord tries to nullify the corresponding
entries in my lists_items table. Because I have that intelligent list,
there are no items stored, but that query would not be a problem, it
would just do nothing but it doesnt work. Rails tries to find the items
in lists_items by the field intelligent_list_id since the has_many
definition is in the intelligent_list class. This behavoir is wrong
because the key is called list_id (I'm using single table inheritance),
so how can I avoid that query? How can I tell active record not to do
anything with items in that lists_items table? Or are there other

The only thing I see right now to avoid that SQL error is adding an
intelligent_list_id column, but that kinda sucks :)
This topic is locked and can not be replied to.