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 :) ) how to associate these models. Thank you in advance for your help. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 19 Mar 2011, at 17:23, "rails.rookie" <bartek.iwaszkiewicz-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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> 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 :) ) > how to associate these models. > Thank you in advance for your help. > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
W dniu 2011-03-19 20:32, Frederick Cheung pisze:> > On 19 Mar 2011, at 17:23, "rails.rookie"<bartek.iwaszkiewicz-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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. > > FredApp 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. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Sat, Mar 19, 2011 at 3:02 PM, Bartek Iwaszkiewicz < bartek.iwaszkiewicz-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> W dniu 2011-03-19 20:32, Frederick Cheung pisze: > > >> On 19 Mar 2011, at 17:23, "rails.rookie"<bartek.iwaszkiewicz-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >> 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 -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Sat, Mar 19, 2011 at 11:45 PM, Bryan Crossland <bacrossland-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> On Sat, Mar 19, 2011 at 3:02 PM, Bartek Iwaszkiewicz < > bartek.iwaszkiewicz-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> W dniu 2011-03-19 20:32, Frederick Cheung pisze: >> >> >>> On 19 Mar 2011, at 17:23, "rails.rookie"<bartek.iwaszkiewicz-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >>> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.