#3 open
Greg Vaughn

ActiveRecord::find issue with :includes

Reported by Greg Vaughn | July 23rd, 2008 @ 05:34 PM

I can't write a complete spec because it'll need a real db. Anyway, let me explain in the context of active_record_persistence_spec.rb as if it were hitting a db.

class Cleaver < ActiveRecord::Base

end

class June < ActiveRecord::Base

include AASM

belongs_to :cleaver

aasm_column :status

end

class Beaver < June

end

describe 'Beavers' do

it "should offer included finds" do

Beaver.find(:first, :include => :cleaver)

end

end

gives

ActiveRecord::ConfigurationError: Association named 'cleaver' was not found; perhaps you misspelled it?

/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/association_preload.rb:39:in `preload_one_association'

/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/association_preload.rb:38:in `each'

/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/association_preload.rb:38:in `preload_one_association'

/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/association_preload.rb:17:in `preload_associations'

/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/association_preload.rb:16:in `preload_associations'

/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/association_preload.rb:16:in `each'

/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/association_preload.rb:16:in `preload_associations'

/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:1343:in `find_every'

/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:1303:in `find_initial'

/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:534:in `find'

/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:544:in `first'

Beaver.first.cleaver works fine. It's just including the association in the find that seems to be the problem.

If I include AASM in Beaver instead of June, life is good.

I'm using Rails 2.1 and rubyist-aasm 2.0.2

Comments and changes to this ticket

  • Greg Vaughn

    Greg Vaughn July 25th, 2008 @ 02:34 PM

    I've been digging and have narrowed this down a bit. For some reason when June includes AASM, inherited_with_inheritable_attributes is not called. This method is aliased to inherited by Rails and sets up the association metadata in Beaver. If I directly call

    June.send :inherited_with_inheritable_attributes, Beaver

    the problem goes away.

    I created a dummy module and included that in June to see if this was a deeper issue in Ruby and/or Rails, but the error does not appear. It's specific to AASM so far as I can tell.

  • Scott Barron

    Scott Barron July 25th, 2008 @ 02:43 PM

    • State changed from “new” to “open”

    Thanks - I'll dig into this and see what I can turn up.

  • Greg Vaughn

    Greg Vaughn July 25th, 2008 @ 03:25 PM

    I have an isolated solution I'm almost happy with. Will update with a

    pull request when ready.

    A deeper solution may be to use an inheritable attribute for the state

    machine. I'll send you a quick fix and decide whether I want to tackle

    that refactoring.

    On Jul 25, 2008, at 1:44 PM, Lighthouse wrote:

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Library for adding state machines to Ruby classes. Includes persistence layers for things like ActiveRecord. Formerly known as acts_as_state_machine.

Pages