Hi, I have an Image table. Currently, Images belong_to or has_and_belongs_to_many to other different models/tables. Currently, Image belongs_to Community. This works great. However, I need to store an image that all Communities "share" (it''s a map of all the Communities -- real estate website). All Communitities should have access to this one particular image. How should that be modeled in the DB and in AR? Thanks, Joe
On Apr 10, 2005 10:43 PM, Joe Van Dyk <joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Currently, Image belongs_to Community. This works great. However, I > need to store an image that all Communities "share" (it''s a map of all > the Communities -- real estate website). All Communitities should > have access to this one particular image. > > How should that be modeled in the DB and in AR?Depending on how you want to do it, you could say Community has_one :image (or has_many depending on your needs), and then assign that one image to all communities. Or, just not both modelling it in any way, stick it in the DB, and then access it directly by ID number. -- Urban Artography http://artography.ath.cx
On 11.4.2005, at 08:00, Rob Park wrote:> On Apr 10, 2005 10:43 PM, Joe Van Dyk <joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> Currently, Image belongs_to Community. This works great. However, I >> need to store an image that all Communities "share" (it''s a map of all >> the Communities -- real estate website). All Communitities should >> have access to this one particular image. >> >> How should that be modeled in the DB and in AR? > > Depending on how you want to do it, you could say Community has_one > :image (or has_many depending on your needs), and then assign that one > image to all communities. > > Or, just not both modelling it in any way, stick it in the DB, and > then access it directly by ID number.yeah: class Community < ActiveRecord::Base def map_image Image.find(XXX) end end Mean and lean :-) //jarkko> > -- > Urban Artography > http://artography.ath.cx > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Joe Van Dyk wrote:> I have an Image table. Currently, Images belong_to or > has_and_belongs_to_many to other different models/tables. > > Currently, Image belongs_to Community. This works great. However, I > need to store an image that all Communities "share" (it''s a map of all > the Communities -- real estate website). All Communitities should > have access to this one particular image. > > How should that be modeled in the DB and in AR?I''ve been using Product has_and_belongs_to_many :media style associations for this kind of stuff. It would also work if I were to allow images for other models though it would need another join table for each one.