0

我不知道,如果物业和业主之间的关系,工作或没有,当我尝试查询我得到这个错误:一个一对多的关系[Ruby on Rails的]

Loading development environment (Rails 3.2.13) 
irb(main):001:0> Owner.find(1).properties 
    Owner Load (18.1ms) SELECT "owners".* FROM "owners" WHERE "owners"."id" = ? LIMIT 1 [["id", 1]] 
    Property Load (0.1ms) SELECT "properties".* FROM "properties" WHERE "properties"."owner_id" = 1 
ActiveRecord::SubclassNotFound: The single-table inheritance mechanism failed to locate the subclass: 'House'. This error is raised because the column 'type' is reserved for storing the class in case of inheritance. Please rename this column if you didn't intend it to be used for storing the inheritance class or overwrite Property.inheritance_column to use another column for that information. 
    from /var/lib/gems/1.9.2/gems/activerecord-3.2.13/lib/active_record/inheritance.rb:143:in `rescue in find_sti_class' 
    from /var/lib/gems/1.9.2/gems/activerecord-3.2.13/lib/active_record/inheritance.rb:136:in `find_sti_class' 
    from /var/lib/gems/1.9.2/gems/activerecord-3.2.13/lib/active_record/inheritance.rb:62:in `instantiate' 
    from /var/lib/gems/1.9.2/gems/activerecord-3.2.13/lib/active_record/querying.rb:38:in `block (2 levels) in find_by_sql' 
    from /var/lib/gems/1.9.2/gems/activerecord-3.2.13/lib/active_record/querying.rb:38:in `collect!' 
    from /var/lib/gems/1.9.2/gems/activerecord-3.2.13/lib/active_record/querying.rb:38:in `block in find_by_sql' 
    from /var/lib/gems/1.9.2/gems/activerecord-3.2.13/lib/active_record/explain.rb:41:in `logging_query_plan' 
    from /var/lib/gems/1.9.2/gems/activerecord-3.2.13/lib/active_record/querying.rb:37:in `find_by_sql' 
    from /var/lib/gems/1.9.2/gems/activerecord-3.2.13/lib/active_record/relation.rb:171:in `exec_queries' 
    from /var/lib/gems/1.9.2/gems/activerecord-3.2.13/lib/active_record/relation.rb:160:in `block in to_a' 
    from /var/lib/gems/1.9.2/gems/activerecord-3.2.13/lib/active_record/explain.rb:34:in `logging_query_plan' 
    from /var/lib/gems/1.9.2/gems/activerecord-3.2.13/lib/active_record/relation.rb:159:in `to_a' 
    from /var/lib/gems/1.9.2/gems/activerecord-3.2.13/lib/active_record/relation/finder_methods.rb:159:in `all' 
    from /var/lib/gems/1.9.2/gems/activerecord-3.2.13/lib/active_record/associations/collection_association.rb:382:in `find_target' 
    from /var/lib/gems/1.9.2/gems/activerecord-3.2.13/lib/active_record/associations/collection_association.rb:335:in `load_target' 
    from /var/lib/gems/1.9.2/gems/activerecord-3.2.13/lib/active_record/associations/collection_proxy.rb:44:in `load_target' 
    from /var/lib/gems/1.9.2/gems/activerecord-3.2.13/lib/active_record/associations/collection_proxy.rb:87:in `method_missing' 
    from /var/lib/gems/1.9.2/gems/railties-3.2.13/lib/rails/commands/console.rb:47:in `start' 
    from /var/lib/gems/1.9.2/gems/railties-3.2.13/lib/rails/commands/console.rb:8:in `start' 
    from /var/lib/gems/1.9.2/gems/railties-3.2.13/lib/rails/commands.rb:41:in `<top (required)>' 
    from script/rails:6:in `require' 

我的财产。 RB文件:

class Property < ActiveRecord::Base 
    attr_accessible :owner_id, :p_city, :p_street, :postcode, :rent, :rooms, :type 
    belongs_to :owner 
    has_one :ticket 
end 

我owner.rb文件:

class Owner < ActiveRecord::Base 
    attr_accessible :address, :f_name, :l_name, :tel_no 
    has_many :properties 
end 

回答

0

,因为它被留作继承的东西,你不能使用 “类型” 为属性/列。您应该将模型的属性和数据库列都更改为其他内容。

+0

你是说我应该重新命名那个叫'type'的属性? – 2013-05-03 06:43:53

+0

是的,你必须改变它,像“property_type”。 – 2013-05-03 06:44:44

+0

是的。您不能使用“type”作为列名称,因为活动 记录使用它来存储ruby类名称(对于单个表 继承)。 ref链接:http://www.ruby-forum.com/topic/101557 – Deepika 2013-05-03 06:45:15