Hi, I''m using an assocation extension as follows: module RequestFinder def open find(:all, :conditions => "buyer_requests.closing_date > \''#{Date.today}\''") end def closed find(:all, :conditions => "buyer_requests.closing_date <= \''#{Date.today}\''") end end with the following ActiveRecord class User < ActiveRecord::Base has_many :my_requests, :class_name => "BuyerRequest", :extend => RequestFinder end In my tests I have a test to check the number of requests. def test_number_of _open_requests john = users(:john) openrequests = john.my_requests.open assert openrequests.count == 1 end Although this returns an array with the correct values my problem is that the count method is undefined. Does anyone know if thats expected behaviour, according the Rails recipes books each of the assocation proxy methods should be available on the returned object i.e. find, create, count etc... Thanks in advance, John -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060705/3f71d9fa/attachment.html
On 7/5/06, John Ward <john.ward@cengal.com> wrote:> Hi, > I''m using an assocation extension as follows: > > module RequestFinder > def open > find(:all, :conditions => "buyer_requests.closing_date > > \''#{Date.today}\''") > end > > def closed > find(:all, :conditions => "buyer_requests.closing_date <> \''#{Date.today}\''") > end > end > > with the following ActiveRecord > > class User < ActiveRecord::Base > has_many :my_requests, :class_name => "BuyerRequest", :extend => > RequestFinder > end > > In my tests I have a test to check the number of requests. > > def test_number_of _open_requests > john = users(:john) > openrequests = john.my_requests.open > assert openrequests.count == 1 > end > > Although this returns an array with the correct values my problem is that > the count method is undefined. Does anyone know if thats expected behaviour, > according the Rails recipes books each of the assocation proxy methods > should be available on the returned object i.e. find, create, count etc...john.my_requests is an association proxy (with the proxy methods defined on it, including those in your extension). john.my_requests.open is just a call to a normal find method, so returns a bog standard array. Tom
Tom, With your clarification I''ve reread the rails recipes statement. "These association proxies have access to all the same methods that would normally be defined on the associations, such as find( ), count( ), and create( )." john.my_requests has these methods so this is correct. Thanks, John ----- Original Message ----- From: "Tom Ward" <tom@popdog.net> To: <rails@lists.rubyonrails.org> Sent: Wednesday, July 05, 2006 1:15 PM Subject: Re: [Rails] Association Extensions> On 7/5/06, John Ward <john.ward@cengal.com> wrote: >> Hi, >> I''m using an assocation extension as follows: >> >> module RequestFinder >> def open >> find(:all, :conditions => "buyer_requests.closing_date > >> \''#{Date.today}\''") >> end >> >> def closed >> find(:all, :conditions => "buyer_requests.closing_date <>> \''#{Date.today}\''") >> end >> end >> >> with the following ActiveRecord >> >> class User < ActiveRecord::Base >> has_many :my_requests, :class_name => "BuyerRequest", :extend => >> RequestFinder >> end >> >> In my tests I have a test to check the number of requests. >> >> def test_number_of _open_requests >> john = users(:john) >> openrequests = john.my_requests.open >> assert openrequests.count == 1 >> end >> >> Although this returns an array with the correct values my problem is that >> the count method is undefined. Does anyone know if thats expected >> behaviour, >> according the Rails recipes books each of the assocation proxy methods >> should be available on the returned object i.e. find, create, count >> etc... > > john.my_requests is an association proxy (with the proxy methods > defined on it, including those in your extension). > john.my_requests.open is just a call to a normal find method, so > returns a bog standard array. > > Tom > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >