这是我第一次创建has_and_belongs_to_many关联,并且它不太合作。无法获得has_and_belongs_to_many关联创建
我的模型
class Server < ActiveRecord::Base
has_and_belongs_to_many :services
和
class Service < ActiveRecord::Base
has_and_belongs_to_many :services
我试图通过创建服务器对象的服务。
我已经得到了服务器对象server = Server.find_by_name(server_name)
,它工作得很好。如果我尝试创建一个服务对象,无论是service = server.services.new
或server.services.create(params)
我得到以下的ActiveRecord错误:
ActiveRecord::HasAndBelongsToManyAssociationForeignKeyNeeded: Cannot create self referential has_and_belongs_to_many association on 'Service#services'. :association_foreign_key cannot be the same as the :foreign_key.
我还没有发现在该错误信息的方式很多,但。我究竟做错了什么?
gah,感谢您排查我的错字。 – Eugene 2012-03-07 17:18:22