Problems with ActiveRecord assoc
- by ciss
Hello again, so i write my e-commerce shop cms and have some strange error:
ActiveRecord::StatementInvalid: Mysql::Error: Unknown column 'id' in 'where clause': DELETE FROM `properties` WHERE `id` = NULL
so, i have three models
Items:
class Item < ActiveRecord::Base
has_many :properties, :dependent => :destroy
has_many :types, :through => :property
end
Type:
class Type < ActiveRecord::Base
has_many :properties, :dependent => :destroy
end
Properties:
class Property < ActiveRecord::Base
belongs_to :item
belongs_to :type
end
So, all is okay, but when i try to item.destroy() i have error =(
This is my test code:
test "should destroy associated properties" do
item = Item.create(:name => "Jeans")
type = Type.create(:key => "color")
property = Property.new
property.item = item
property.type = type
property.save
item.destroy()
end