Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

There was a problem

This project is archived and is in readonly mode.

after_find and after_initialize can't access table attributes

#5589

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?

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

State: duplicate
Milestone: none
Assigned to: nobody
Importance: Low