Forum: Ruby on Rails 3 models -> 1 image

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.
A5d8283732da86365736508fef6c1c67?d=identicon&s=25 Nuno (Guest)
on 2006-04-15 20:31
Hello, I have 3 models (Galery, Product, News) which all have 0 or 1
Image

I don't understand what the relationship between the 3 models and the
Image model should be.

I might goes to Galery has_one Image, Product has_one Image and News
has_one Image but I presume that active record will rely on Image model
having a foreign key related to only one owner model (eg.
Image.galery_id), which can't be the case.

Any hint appreciated, thank you
43ec5998360a0cc21b51afef1781e9c0?d=identicon&s=25 Daniel Higginbotham (Guest)
on 2006-04-15 20:58
(Received via mailing list)
How about having your Gallery, Product, and News belongs_to Image?
A5d8283732da86365736508fef6c1c67?d=identicon&s=25 Nuno (Guest)
on 2006-04-15 22:55
Doesn't sound natural for me...

I've found this thread (http://www.ruby-forum.com/topic/61327) and the
last answer close to my feelings about belongs_to.

I don't know if this solution is the right one.

Any thought about this ?
This topic is locked and can not be replied to.