相关疑难解决方法(0)

Mongoid ::错误:: MixedRelations

我有一个用户模型嵌入" 一对多 "的关注列表,如下所示:

class User 
  include Mongoid::Document

  field :uid
  field :name     
  field :user_hash

  embeds_many :watchlists
end


class Watchlist
  include Mongoid::Document

  field :html_url
  field :description

  #field :name
  field :fork_, :type => Boolean

  field :forks, :type => Integer
  field :watchers, :type => Integer

  field :created_at, :type => DateTime
  field :pushed_at, :type => DateTime

  field :avatar_url

  embedded_in :user
  has_and_belongs_to_many :tags
end
Run Code Online (Sandbox Code Playgroud)

监视列表还应引用多对多 Tag模型,反之亦然:

class Tag
  include Mongoid::Document
  field :name, type: String

  has_and_belongs_to_many :watchlists
end
Run Code Online (Sandbox Code Playgroud)

无论如何,这导致了一个错误,似乎不可能出现这种"混合"关系:

Mongoid::Errors::MixedRelations (Referencing a(n) Watchlist document from the …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails mongodb mongoid

3
推荐指数
1
解决办法
1560
查看次数

标签 统计

mongodb ×1

mongoid ×1

ruby-on-rails ×1