【发布时间】:2011-07-26 14:56:12
【问题描述】:
我的模型:
class CardSignup < ActiveRecord::Base
has_one :conversion
has_one :card_signup, :through => :conversion
class User < ActiveRecord::Base
has_many :conversions
has_many :card_signups, :through => :conversions
class Conversion < ActiveRecord::Base
belongs_to :card_signup
belongs_to :user
end
我的迁移:
class AddCardSignupConversions < ActiveRecord::Migration
def self.up
create_table (:conversions, :id => false) do |t|
t.integer :user_id
t.integer :card_signup_id
end
end
def self.down
drop_table :conversions
end
end
现在,我可以成功查找了:
User.find(x).conversions
CardSignup.find(x).conversion
但是,我无法向这些链接添加任何对象。不知道为什么..我试过这个:
User.last.conversions << CardSignup.last
返回:
ActiveRecord::AssociationTypeMismatch: Conversion(#2183228680) expected, got CardSignup(#2183113520)
这是为什么呢?
【问题讨论】:
标签: mysql ruby-on-rails model