rick.denatale-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Apr-26 15:45 UTC
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? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
MichaelLatta
2007-Apr-26 22:56 UTC
Re: ActiveRecord association not seen in rake db:migrate
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...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <rick.denat...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jodi Showers
2007-Apr-26 23:02 UTC
Re: ActiveRecord association not seen in rake db:migrate
On 26-Apr-07, at 6:56 PM, MichaelLatta wrote:> > 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...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" > <rick.denat...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> 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? > >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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---