Forum: Ruby on Rails many to one :through another

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.
D5145c421cd25af6fa577c15219add90?d=identicon&s=25 unknown (Guest)
on 2006-03-31 12:13
(Received via mailing list)
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
9f0f89bbd9e1ecfbaab6584e429b7a2f?d=identicon&s=25 Josh Susser (jsusser)
on 2006-03-31 16:52
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 Susser
http://blog.hasmanythrough.com
This topic is locked and can not be replied to.