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?
on 2007-04-26 17:46
on 2007-04-27 00:57
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 On Apr 26, 8:45 am, "rick.denat...@gmail.com"
on 2007-04-27 01:03
On 26-Apr-07, at 6:56 PM, MichaelLatta wrote: > >> :conditions => "transaction_type LIKE '%verify' AND >> end >> 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? > > 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