Problem with Associations idea

Hi, i have two models:

User<…
has_many :photos, :dependent => :destroy

Photo<…
belongs_to :user

and I need Attribute model such as each photo has many attributes.
And here I’m not sure whether Attribute should be has_many: photos or
belongs_to :photo.
Moreover i need to use on photos and attributes FCA algorism to build
lattice and perhaps write it to db.
So do I need next model (eg. Lattice), maybe I should use
has_many :through ?
I use rails three weeks so I please for help as simple example
( doesn’t have to be pro :slight_smile: )
how to associate these models.
Thank you in advance for your help.

On 19 Mar 2011, at 17:23, “rails.rookie” [email protected]
wrote:

and I need Attribute model such as each photo has many attributes.
And here I’m not sure whether Attribute should be has_many: photos or
belongs_to :photo.
Can you give some examples of what your attributes are? You probably
want to avoid calling the association attributes - that will collide
with an internal activerecord method.

Fred

W dniu 2011-03-19 20:32, Frederick C. pisze:

belongs_to :user

and I need Attribute model such as each photo has many attributes.
And here I’m not sure whether Attribute should be has_many: photos or
belongs_to :photo.
Can you give some examples of what your attributes are? You probably want to
avoid calling the association attributes - that will collide with an internal
activerecord method.

Fred
App has to work in this way, user add photo and then add attributes to
photo on example (Baltic Sea.jpg; sea, water, sand ).
Then usning Formal concept analysis (not relevant) special paris are
created {(photo,…,photo n),(attribute,…,attribute n)}
and it should be remember in some way (i suppose best will be another
table), because it will be modefied when photo table or
attribute table will change.
I can’t find out the best way how associations between models should
look like and how many models i need.

Bartek.

On Sat, Mar 19, 2011 at 3:02 PM, Bartek Iwaszkiewicz <
[email protected]> wrote:


to avoid calling the association attributes - that will collide with an
attribute table will change.
I can’t find out the best way how associations between models should look
like and how many models i need.

You are going to want to do a has_many in the Photo model to
PhotoAttribute
model. This will allow you to have the PhotoAttribute model be a list of
all
the attributes that a photo can have. From what you explained this sound
like what you wanted to do with that table anyway. Your final models
would
look like this:

class User < ActiverRecord::Base
has_many :photos, :dependent => :destroy
end

class Photo < ActiveRecord::Base
belongs_to :user
has_many :photo_attributes
end

class PhotoAttribute < ActiveRecord::Base

On Sat, Mar 19, 2011 at 11:45 PM, Bryan C.
[email protected]wrote:

belongs_to :photo.
created {(photo,…,photo n),(attribute,…,attribute n)}
like what you wanted to do with that table anyway. Your final models would
end

class PhotoAttribute < ActiveRecord::Base

Sorry, I hit “Send” before I finished typing and proofing. Below is the
corrected and finished model layout. You don’t want to use Attribute as
the
name of a model or table.

class User < ActiverRecord::Base

has_many :photos, :dependent => :destroy
end

class Photo < ActiveRecord::Base
belongs_to :user
has_many :photo_attributes
end

class PhotoAttribute < ActiveRecord::Base
belongs_to :photo
belongs_to :photo_descriptor
end

class PhotoDescriptor < ActiveRecord::Base
has_many :photo_attributes
end

Your PhotoDescriptor model would be the list of descriptions/attributes
found in the photo (sea,green,sand,etc.).

B.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs