class Client < ActiveRecord::Base
has_many :contact_cards
has_many :business_contacts,
:through => :contact_cards,
:source => :contact, <= 跟 as => :this_item 的this_item 一樣
:source_type => 'Business'
end
class Business < ActiveRecord::Base
has_many :contact_cards, :as => :contact
end
class ContactCard < ActiveRecord::Base
belongs_to :client
belongs_to :contact, :polymorphic => true
end
User.first.business_cards <= 第一個user的contact card of bussiness category
沒有留言:
張貼留言