使用{ _id: ObjectID { _bsontype: 'ObjectID', id: 'W_?àÅÜY¼-íbO' }, // <- Problem
salt: 'ULRtWgj0qgblPRbSPwTe4A==',
displayName: 'test tester',
provider: 'local',
username: 'tester',
created: Tue Jun 14 2016 06:36:48 GMT+0200 (Romance Daylight Time),
roles: [ 'user' ],
profileImageURL: 'modules/users/client/img/profile/default.png',
referrers: { level1: ObjectID { _bsontype: 'ObjectID', id: 'W^_ó 5IE\u0013
N\u0010c' } }, // <- Also problem
password: 'jXpp+RJIegHFKD50sL2aOlOUhE0rvYtSJZIDB244SDIw93yrbuFCTUJK3SZIs3F
w0DdHOUzlQoLQwTGEcF67Kg==',
email: 'test@example.com',
lastName: 'tester',
firstName: 'test',
__v: 0
}
和{
"_id" : ObjectId("575f89e0c5dc59bc2ded62d5"), // <- This is different!
"salt" : "ULRtWgj0qgblPRbSPwTe4A==",
"displayName" : "test tester",
"provider" : "local",
"username" : "tester",
"created" : ISODate("2016-06-14T04:36:48.130Z"),
"roles" : [
"user"
],
"profileImageURL" : "modules/users/client/img/profile/default.png",
"referrers" : {
"level1" : ObjectId("575ebef32035ccc8134e1063") // <- This too!
},
"password" : "jXpp+RJIegHFKD50sL2aOlOUhE0rvYtSJZIDB244SDIw93yrbuFCTUJK3S
ZIs3Fw0DdHOUzlQoLQwTGEcF67Kg==",
"email" : "test@example.com",
"lastName" : "tester",
"firstName" : "test",
"__v" : 0
}
>
时出现问题,我有以下两种模式:
has_many
此帐户模型
belongs_to
我试图运行此查询:
@primary_key {:guid, :integer, []}
schema "characters" do
field :name, :string
field :race, :integer
field :class, :integer
field :gender, :integer
field :level, :integer
field :xp, :integer
field :money, :integer
field :online, :integer
field :totaltime, :integer
field :leveltime, :integer
field :rest_bonus, :float
field :is_logout_resting, :integer
field :honor_highest_rank, :integer
field :honor_standing, :integer
field :stored_honor_rating, :float
field :stored_dishonorable_kills, :integer
field :stored_honorable_kills, :integer
field :health, :integer
field :power1, :integer
field :power2, :integer
field :power3, :integer
field :power4, :integer
field :power5, :integer
belongs_to :account, Pugit.Account, references: :id
end
这里唯一的重大区别是,我可能试图从另一个仓库(其他数据库)预加载
但是我收到了这个错误:
schema "account" do
field :username, :string
field :sha_pass_hash, :string
field :gmlevel, :integer, default: 0
field :sessionkey, :string
field :v, :string
field :s, :string
field :email, :string
field :joindate, Ecto.DateTime
field :last_ip, :string, default: "0.0.0.0"
field :failed_logins, :integer, default: 0
field :locked, :integer, default: 0
field :last_login, Ecto.DateTime
field :active_realm_id, :integer, default: 0
field :expansion, :integer, default: 0
field :mutetime, :integer, default: 0
field :locale, :integer, default: 0
has_many :characters, PugitWow.Character, foreign_key: :account
end
任何信息都会很棒,谢谢
我的Pugit.AccountRepo.all(Pugit.Account) |> Pugit.CharRepo.preload([:characters])
表的主键是** (Ecto.QueryError) deps/ecto/lib/ecto/association.ex:320: field `Pugit.Character.account` in `where` does not exist in the model source in query:
from c in Pugit.Character,
where: c.account in ^[1, 2, 3, 4, 21],
order_by: [asc: c.account]
(elixir) lib/enum.ex:1473: Enum."-reduce/3-lists^foldl/2-0-"/3
(elixir) lib/enum.ex:1151: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
(ecto) lib/ecto/repo/queryable.ex:91: Ecto.Repo.Queryable.execute/5
(ecto) lib/ecto/repo/queryable.ex:15: Ecto.Repo.Queryable.all/4
(elixir) lib/enum.ex:1088: Enum."-map/2-lists^map/1-0-"/2
我的characters
表的外键是guid
我的characters
表的主键是account
答案 0 :(得分:2)
这种情况正在发生,因为您的account
关联使用的名称与外键account
的字段相同。将该字段重命名为account_id
,然后将其用作关联:
belongs_to :account, Pugit.Account