[Rails] Re: how to retrieve single record through chained associations

2009-03-11 Thread Tod Tod
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

[Rails] Re: how to retrieve single record through chained associations

2009-03-08 Thread Tod Tod
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

[Rails] Re: how to retrieve single record through chained associations

2009-03-08 Thread Tod Tod
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. oops, should be shop_categories Tod ps. hmm, here posts don't

[Rails] Re: how to retrieve single record through chained associations

2009-03-07 Thread rainer54
Hi Tod For finding the category 10 of shop 1, the following should work by using Activerecord associations Shop.find(1).categories.find(10) or Shop.find(1).categories.find(:first, :conditions = 'category = 10') rainer Dharmdip Rathod wrote: Hi I have a standard associations

[Rails] Re: how to retrieve single record through chained associations

2009-03-07 Thread Tod Tod
Hi rainer54 Actually Shop.find(1).categories.find(10) and Shop.find(1).categories.find(:first, :conditions = 'category_id = 10') are the different ways to retrieve same category record in association with shop 1. But going further with association I need to retrieve records from

[Rails] Re: how to retrieve single record through chained associations

2009-03-07 Thread Tod Tod
Hi Frederick Thanks for answer. I'm just trying to investigate why it is not chained whole over all associations. I think that each association shuold act as maybe proxy and pass from begining Shop.find(1) till the end of this chainings and pass Shop record. It sounds to me naturally way of

[Rails] Re: how to retrieve single record through chained associations

2009-03-07 Thread haneef5k
can u tell me online tutorial..??? On Mar 7, 10:55 pm, Frederick Cheung frederick.che...@gmail.com wrote: On Mar 7, 4:39 pm, Tod Tod rails-mailing-l...@andreas-s.net wrote: Logically this kind of chaining Shop.find(2).category.find(10).shop_categories should collect and join

[Rails] Re: how to retrieve single record through chained associations

2009-03-07 Thread Frederick Cheung
On Mar 7, 6:08 pm, Tod Tod rails-mailing-l...@andreas-s.net wrote: I'm just trying to investigate why it is not chained whole over all associations. I think that each association shuold act as maybe proxy and pass from begining Shop.find(1) till the end of this chainings and pass Shop

[Rails] Re: how to retrieve single record through chained associations

2009-03-07 Thread rainier
ok - misunderstood this The solution is already given by Fred On 7 Mrz., 19:01, Tod Tod rails-mailing-l...@andreas-s.net wrote: Hi rainer54 Actually Shop.find(1).categories.find(10) and Shop.find(1).categories.find(:first, :conditions = 'category_id = 10') are the different ways to