一对多关联无法正常工作

时间:2015-12-30 07:31:08

标签: ruby-on-rails activerecord

我的模特是

class TelecomOperator < ActiveRecord::Base
has_many :users

class User < ActiveRecord::Base
belongs_to :telecom_operator

当我 TelecomOperator.first.users 时,它给了我所有用户但是当我做的时候 User.first.telecom_operator 它总是给我零

SELECT  "users".* FROM "users" WHERE "users"."deleted_at" IS NULL AND "users"."id" = $1 LIMIT 1  [["id", 2]]
=> nil 

当我这样做时

User.includes(:telecom_operator).find(2)

工作正常

0 个答案:

没有答案