我有两个实体,Project
并且Domain
. 项目has_many
域和域belongs_to
项目,但domain_id
存储到项目表中。
在 rails c 我试过
p = Project.first
d = Domain.where(id: p.domain_id)
我得到了
Domain Load (0.2ms) SELECT "domains".* FROM "domains" WHERE "domains"."id" = 1
=> #<ActiveRecord::Relation [#<Domain id: 1, name: "alex.com", created_at: ...">]>
当我尝试
d.name
=> 结果是“域”而不是 alex.com
2.0.0-p247 :007 > d.name
=> "Domain"
为什么会这样?
谢谢