| Issue 6: | Rename the product self referential has_and_belongs_to_many association (related_products) | |
| 1 person starred this issue and may be notified of changes. | Back to list |
Version used: substruct_rel_0-97
The self referential has_and_belongs_to_many relationship of the product
class was given a name that don't permits it to take full advantage of the
automatically added methods to manipulate the collection of associated
objects. You can add but you cannot delete related products (now I see why
the SQL was created)
Changing
has_and_belongs_to_many :related_products
...
to
has_and_belongs_to_many :related
...
let you ged rid of that ugly SQL command:
def remove_return_relation(relative)
sql = "DELETE FROM related_products "
sql << "WHERE product_id = #{relative.id} AND related_id = #{self.id}"
ActiveRecord::Base.connection.execute(sql)
end
doing something like that:
def remove_return_relation(relative)
relative.related.delete(self)
end
I don't know if you can maintain the same association name.
Feb 10, 2008
#2
edmundo...@gmail.com
Feb 11, 2008
Please close this issue as don't making sense. I really had funny results testing different times. 1. The name of the relation doesn't make any difference. 2. Don't using SQL at the callback of the return relation creates at best performance problems or infinite calls. 3. The way related products are beeing assigned doesn't seems to make difference if a product is new or not, (for this I had problems before, but I can't reproduce them again, and I didn't discovered why it happened).
Feb 12, 2008
(No comment was entered for this change.)
Status:
Invalid
|