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 <[email protected]> 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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---