Many to one :through another


#1

Since has_one :colour :through => :species isn’t supported (for some
reason unknown to me), can anyone forsee any problems that the
following workaround might cause (in the Photo class).

has_many :artists, :through => :artist_photos
has_one :artist_photo

So effectively, the has_many statement gives me the through
functionality I need, but the has_one restricts the program to only
one artist for each photo. I know this might seem like a silly
question, but go easy, I’ve been doing this less than a week.
Thanks,
Nathan


#2

unknown wrote:

Since has_one :colour :through => :species isn’t supported (for some
reason unknown to me), can anyone forsee any problems that the
following workaround might cause (in the Photo class).

has_many :artists, :through => :artist_photos
has_one :artist_photo

So effectively, the has_many statement gives me the through
functionality I need, but the has_one restricts the program to only
one artist for each photo. I know this might seem like a silly
question, but go easy, I’ve been doing this less than a week.
Thanks,
Nathan

thing.species.colour isn’t terse enough? Or are you trying to optimize
the number of queries to get to the colour attribute?

You can simulate has_one with a has_many with an :order and :limit => 1
(though the naming is still plural, not singular).


Josh S.
http://blog.hasmanythrough.com