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?