On Sat, Mar 19, 2011 at 11:45 PM, Bryan Crossland <bacrossl...@gmail.com>wrote:

> On Sat, Mar 19, 2011 at 3:02 PM, Bartek Iwaszkiewicz <
> bartek.iwaszkiew...@gmail.com> wrote:
>
>>  W dniu 2011-03-19 20:32, Frederick Cheung pisze:
>>
>>
>>> On 19 Mar 2011, at 17:23, "rails.rookie"<bartek.iwaszkiew...@gmail.com>
>>>  wrote:
>>>
>>>  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.
>>>>
>>> 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.
>>
>
> 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
>



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.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to