I have 3 classes, Schema, Entity and Property, representing the DB design business. The Schema-Entity seems work, but Entity-Property does not.
class Hx::Entity < ActiveRecord::Base
belongs_to :schema
attr_accessible :name
has_many :properties , class_name: "Hx::Property" , primary_key: "id"
end
class Hx::Property < ActiveRecord::Base
attr_accessible :destination, :indexed, :inverse, :isToMany, :kind, :name, :optional, :transient , :type
belongs_to :entity
end
When I run entity_obj.properties, it throws the error undefined method primary_key' for String:Class
.
I twist around the has_many's options, but it does not help.
Does anyone has any idea on this?
Thanks.
Thank you muttonlamb!
I figured out the problem.
In the beginning, I guess the problem is around has_many
since that is where it appears. But it is not the case. even i do not define class_name
, Rails still can find the class.
Later on I found some record show up that the attribute type
in Property
is not assigned a value. The root cause is that I override superclass's attribute !
The solution:
ActiveRecord::Migration.rename_column :hx_properties , :type, :datatype
I think you need to drop the "" around HX::Property
The error message is telling you that it is trying to call primary key on an object of String:Class
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With