Enumerable methods on has_many associations?

I just tried upgrading our application to Rails 2.1 on JRuby 1.1.2,
ActiveRecordJDBC 0.8.1 (the versions that are bundled with the nightly
build of NetBeans). The problem I’m having seems to be calling ‘min’
on an association. Here is a simple example:

require ‘rubygems’
gem ‘activerecord’
gem ‘activerecord-jdbc-adapter’
require ‘active_record’

ActiveRecord::Base.establish_connection({
:adapter => ‘mysql’,
:driver => ‘com.mysql.jdbc.Driver’,
:host => ‘localhost’,
:database => ‘sandbox_dev’,
:username => ‘root’
})

class Person < ActiveRecord::Base; has_many :addresses; end
class Address < ActiveRecord::Base; belongs_to :person; end

person = Person.find :first
puts person.addresses.first.street1
puts person.addresses.min{|a,b| a.street1 <=> b.street1}

The second last line is just there to verify that the objects in the
collection respond to street1. The last line produces this:

/lib/main.rb:19: undefined method street1' for #<Array:0xb85495> (NoMethodError) from /jruby-1.1.2/lib/ruby/gems/1.8/gems/activerecord-2.1.0/ lib/active_record/associations/association_collection.rb:274:inmethod_missing’
from /jruby-1.1.2/lib/ruby/gems/1.8/gems/activerecord-2.1.0/
lib/active_record/associations/association_proxy.rb:175:in each' from /jruby-1.1.2/lib/ruby/gems/1.8/gems/activerecord-2.1.0/ lib/active_record/associations/association_proxy.rb:175:inmin’
from /jruby-1.1.2/lib/ruby/gems/1.8/gems/activerecord-2.1.0/
lib/active_record/associations/association_proxy.rb:175:in
method_missing' from /jruby-1.1.2/lib/ruby/gems/1.8/gems/activerecord-2.1.0/ lib/active_record/associations/association_collection.rb:274:inmethod_missing’
from /lib/main.rb:19

This code (minus the inclusion of the jdbc adapter) works fine in
MRI. Any suggestions?

thanks,
Darcy.


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Thu, Jun 26, 2008 at 8:41 AM, Darcy S. [email protected]
wrote:

ActiveRecord::Base.establish_connection({
person = Person.find :first
method_missing' /jruby-1.1.2/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/associations/association_collection.rb:274:in method_missing’
from /lib/main.rb:19

This code (minus the inclusion of the jdbc adapter) works fine in MRI. Any
suggestions?

Sorry, I don’t have any, but since you have a nice reduced test case,
I’d encourage you to file a bug on it.

Thanks,
/Nick


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Jun 26, 2008, at 11:02 AM, Nick S. wrote:

On Thu, Jun 26, 2008 at 8:41 AM, Darcy S. [email protected]
wrote:

Sorry, I don’t have any, but since you have a nice reduced test case,
I’d encourage you to file a bug on it.

There’s already http://jira.codehaus.org/browse/JRUBY-2472, which
seems to be the same issue. I think
ActiveRecord::Asssociations::AssociationCollection does something odd
with block arguments in its method_missing.

:dudley


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email