Forum: Ruby on Rails repeating has_many calls on the same model

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F719c6cb34bd5b691c12b373b7244b4d?d=identicon&s=25 Dorian Mcfarland (tachekent)
on 2006-05-18 06:36
(Received via mailing list)
Hi,

I currently have a model with (amongst others) the following
declarations in it:

  has_many                :live_action_personnel,
                          :class_name => "Credit",
                          :include => :credit_type,
                          :order => 'credit_types.position,
credits.position ASC',
                          :group => 'credit_types.personnel_type',
                          :conditions =>
'credit_types.personnel_type="live_action_personnel"'

  has_many                :production_personnel,
                          :class_name => "Credit",
                          :include => :credit_type,
                          :order => 'credit_types.position,
credits.position ASC',
                          :group => 'credit_types.personnel_type',
                          :conditions =>
'credit_types.personnel_type="production_personnel"'

so the association is on 'Credit' both times, but with a sql condition.

Is this a bad thing to do?
Am I likely to suffer as-yet unknown horrible consequences doing such a
thing?

I considered using single table inheritance, but that's not really much
use because the condition is dependent upon a 2nd order association.

Just wanted to check...

dorian

--
I do things for love or money
9f0f89bbd9e1ecfbaab6584e429b7a2f?d=identicon&s=25 Josh Susser (jsusser)
on 2006-05-18 09:25
dorian mcfarland wrote:
> so the association is on 'Credit' both times, but with a sql condition.
>
> Is this a bad thing to do?
> Am I likely to suffer as-yet unknown horrible consequences doing such a
> thing?

Not at all.  I use special associations (need a better term for them)
frequently to simplify access using conditions.

--
Josh Susser
http://blog.hasmanythrough.com
This topic is locked and can not be replied to.