2008年10月28日 星期二

has_many,through,source,source_type,foregin_key,class_name


#我發表過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'}

沒有留言: