Hi, I see that nobody knows how to do better way.
So maybe someone could suggest different model design that I can do @category.active And just to avoid calling this self.merchant_categories.find_by_category_id(id).active def active self.merchant_categories.find_by_category_id(id).active end instead to call self.merchant_category.active Thanks, Tod Tod Tod wrote: > Hi and thanks, > > yes this works Shop.find(2).shop_categories.find_by_category_id(10) > > In shop_categories table I have field 'active' to mark that a category > is visible/active for the shop. > > So what is the best way to retrieve this value for shop's category? > > In Category model I have defined 'active' so I can fetch with > @category.active or > @categories.each do |category| > <%= category.name %> > <%= category.active %> > end > > > def active > self.merchant_categories.find_by_category_id(id).active > end > > I know that this is not so good solution, but I could not figured out > over way to get this value. It is realy over kill for server. And It > would get harder if there are more values that I need to keep in > merchant_categories. > > Is there a better way to do it? > > > Tod > > > > > > Frederick Cheung wrote: >> On Mar 7, 6:08�pm, Tod Tod <rails-mailing-l...@andreas-s.net> wrote: >>> am I right? >>> >> don't know about DataMapper. In activerecord as soon as you call find >> you'll get a normal record/array of records. if you just want >> something that adds some extra conditions then you may be interested >> in named_scope. The other thing is that (in active record) scopes >> scope a particular table, so when you do Shop.find(1).categories then >> the categories proxy there is scoping finds on Category to those with >> the appropriate shop_id - it's not magic thing across everything with >> a shop_id column. >> >> Fred >> >> >> Fred -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---