Created
March 27, 2012 08:09
-
-
Save gamov/2213902 to your computer and use it in GitHub Desktop.
Delegate fails via a :through relationship until model is saved
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ReturnedItem < AR:Base | |
belongs_to :sold_item | |
delegate :unit_price, :to => :sold_item | |
has_one :item_variant, :through => :sold_item | |
delegate :full_name, :sku, :packaging, :uom_string, :to => :item_variant | |
end | |
#item_variant is another AR model | |
## | |
#My problem is | |
ReturnedItem.new(:sold_item => an_saved_sold_item).full_name => | |
RuntimeError: ReturnedItem.full_name delegated to item_variant.full_name, but item_variant is nil | |
#even though the item_variant exist | |
#if i save the newly record, then, it works. | |
# Ruby 1.9.2 / Rails 3.0.10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment