#我發表過forum的comments
has_many :forum_comments, :through => :forums, :source => :comments
#forum 裡有我的 comments的 forum, 找出 forum array
has_many :forums_has_comments,
:through => :comments,
:source => :record,
:source_type => 'Forum'
#我在forum 裡所有的comments, 找出 comments array
has_many :comments_in_forums,
:foreign_key => :user_id,
:class_name => 'Comment',
:conditions => {:record_type => 'Forum'}
2008年10月28日 星期二
has_many,through,source,source_type,foregin_key,class_name
標籤:
class_name,
foregin_key,
has_many,
source,
source_type,
through
2008年10月27日 星期一
Has_one with :source_type
http://www.javaeye.com/topic/129195
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
標籤:
has_one,
source_type
訂閱:
文章 (Atom)