I am learning to use ActiveRecord so bear with me. I have a script that looks like this
class Product < ActiveRecord::Base set_primary_key "ProductID" set_table_name "Product" has_many :variants, :foreign_key => 'ProductID' end
class Variant < ActiveRecord::Base set_primary_key "VariantID" set_table_name "ProductVariant" belongs_to :product, :foreign_key => 'ProductID' has_one :capacity, :foreign_key => 'CapacityID' has_one :material, :foreign_key => 'MaterialID' end
class Capacity < ActiveRecord::Base set_primary_key "CapacityID" has_many :variants, :foreign_key => 'CapacityID' end
class Material < ActiveRecord::Base set_primary_key "MaterialID" has_many :variants, :foreign_key => 'MaterialID' end
widget = Product.find("10") puts widget.Name puts '-------------------------------------'
widget.variants.each do |v| puts v.Name.squeeze(" ").chop! + "\t\t In stock: \t" + v.Inventory.to_s + "\tPrice: \t" + v.Price.to_s + "\tCapacity: \t" + v.capacity.Name.to_s puts "\t Material: \t" + v.material.Name.to_s # this line breaks the script
end
The "puts "\t Material: \t" + v.material.Name.to_s" line in the do loop triggers the following error:
B2