0

シナリオ: Rails + Mongoid + Rabl

私は次のようなクラスを持っています

class User
   has_many :cards
   field    :name

class Card
   belongs_to :user
   field      :anotheruser, type:Moped::BSON::ObjectId

私は rabl 初心者なので、そこにいる rabl の専門家への私の質問は、rabl から直接 BSON:ObjectId を介して「別のユーザー」オブジェクトを照会するエレガントな方法があるということです。確かにコントローラーで魔法を実行できますが、利用可能であれば非常に便利な機能です。

ありがとう。

P

4

1 に答える 1

0

あなたのクラスは間違っているように見えます。

class User
  include Mongoid::Document
  has_and_belongs_to_many :cards
  field    :name

class Card
   include Mongoid::Document
   has_and_belongs_to_many :user

user.cards通常の関係を使用できるはずです。cards.users

于 2013-03-15T19:17:07.343 に答える