ActiveRecord association not seen in rake db:migrate

I'm having trouble getting a migration to work.

I've got an Account model with the following association:

  has_one :last_verified_payment,
           :class_name => 'AuditEntry',
           :order => 'updated_at DESC',
     :conditions => "transaction_type LIKE '%verify' AND content LIKE
'%txn_type=subscr_payment%'"

I've got another model Subscription which belongs_to :account, and has
a method

def calculate_last_payment_date
    lvp = account.last_verified_payment
    ...
end

When I try to use this method in a migration, it throws a NoMethod
error for :last_verified_payment.

This only happens in the migration though. The migration didn't touch
either the accounts nor audit_entries tables. I've even gone so far
as running rake db:migrate under rdebug, and stopping just before the
call to account.last_verified_payment, displaying which Account
instance it's using, verifying that the NoMethod is being raised, and
in a parallel console session, getting the same Account and
Subscription, and invoking both the
Subscription#calculate_last_payment_date, and the
Account#last_verified_payment successfully.

Any ideas what's going on?

I can not verify this from personal experience, but I have seen posts
indicating that when a migration is run all you have access to is
database fields not the full model classes.

I think the idea is that the migrations are operating on the database
not on the model and should use SQL directly for any data manipulation
that is required within the migration.

Michael

define your migration class with associations - then you'll have access to the associations.

Class MyMigration < ActiveRecord::Migration

   class Blog< ActiveRecord::Base
     has_many :entries
   end

def self.up
   end

...

  cheers,
Jodi