我有一个嵌入许多 email_accounts 的用户。同时我希望 email_accounts 可以有多个 email_templates。这可能吗?当我尝试合并它时,我的 Rails 应用程序拒绝接受关系。
我希望进行如下查询:
email_template = EmailTemplate.first
email_template.email_account = current_user.email_accounts.where(:_id => params[:email_account_id).first
以下是关系:
class User
include Mongoid::Document
embeds_many :email_accounts, :inverse_of => :user
has_many :email_templates, :inverse_of => :user
end
class EmailAccount
include Mongoid::Document
embedded_in :user, :inverse_of => :email_accounts
has_many :email_templates :inverse_of => :email_account
end
class EmailTemplate
include Mongoid::Document
belongs_to :user, :inverse_of => :email_templates
belongs_to :email_account, :inverse_of => :email_templates
end