When I try to "put" or "<%=" an ActiveRecord (rails) attribute, I get nil, but when I look at the object hash its actually there

StackOverflow https://stackoverflow.com/questions/15794852

Question

So here is an example of a hash for a record of the 'properties' table, the attribute in question being 'owner'

Property.first #=>
  #<Property id: 3684, ss_property_id: 1, owner_full_name: "Holliday Associates", owner: "HA",
  owners_pctg: 100, tax_map_id: "0460001047", county: "Horry", description: "L.S. Alford", acreage:
  131.0, prop_taxes_2009: 180.72, prop_taxes_2010: 173.99, prop_taxes_2011: 172.94, notes: nil,
  created_at: "2013-04-03 01:16:23", updated_at: "2013-04-03 01:16:26">

When I do something like this, however

1.9.3p194 :011 > Property.first.owner
Property Load (0.3ms)  SELECT "properties".* FROM "properties" LIMIT 1
=> nil

it is nil.

EDIT: here is my model (dramatically over-simplified...)

class Property < ActiveRecord::Base
  belongs_to :owner
end
Was it helpful?

Solution

My model ended up having a conflict with the :owner namespace. It actually belongs_to :owner, a new model I haven't even started using yet. The :owner namespace apparently got overwritten by the ActiveRelation method to the Owner model

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top