This project is archived and is in readonly mode.

#5589 ✓duplicate
drhenner (at yahoo)

after_find and after_initialize can't access table attributes

Reported by drhenner (at yahoo) | September 9th, 2010 @ 06:53 AM

I have

  def after_find

@beginning_tax_rate_id      = self.tax_rate_id # this stores the initial value of the tax_rate
@beginning_shipping_rate_id = self.shipping_rate_id # this stores the initial value of the tax_rate
@beginning_total            = self.total # this stores the initial value of the total



end
When I do the following, I get this in the console:
ruby-1.8.7-p302 > items = OrderItem.includes([{:variant => :product}]).where(['order_items.order_id = ? AND products.shipping_category_id = ?', 10, 3])
ActiveModel::MissingAttributeError: missing attribute: tax_rate_id

from /Users/davidhenner/.rvm/gems/ruby-1.8.7-p302@my_app/gems/activerecord-3.0.0.rc2/lib/active_record/attribute_methods.rb:44:in `send'
from /Users/davidhenner/.rvm/gems/ruby-1.8.7-p302@my_app/gems/activerecord-3.0.0.rc2/lib/active_record/attribute_methods.rb:44:in `method_missing'
from /Users/davidhenner/projects/myhadean/Hadean/app/models/order_item.rb:12:in `after_find'</code>



This works if I just do OrderItem.find(id). Is this a bug or do I need to change my method?

Comments and changes to this ticket

Create your profile

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

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages