0
votes

Scenario: Rails + Mongoid + Rabl

I have a classes like

class User
   has_many :cards
   field    :name

and

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

I'm rabl newbie so my question for you rabl experts out there is that is there an elegant way to query "anotheruser" object via BSON:ObjectId straight from rabl. I can do the magic in my controller for sure, but it would be very handy feature if available.

Thanks.

P

1

1 Answers

0
votes

Your classes look wrong, should look like

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

class Card
   include Mongoid::Document
   has_and_belongs_to_many :user

You should be able to use the normal relationships user.cards and cards.users