0
class User
include Mongoid::Document
has_and_belongs_to_many :contacts, class_name: 'User'
field :username, :type => String
field :email, :type => String
field :time_zone, :type => String
我想要的是當我調用current_user.contacts.to_json以僅獲取每個聯繫人的用戶名和電子郵件屬性時。我試圖覆蓋to_json,但似乎沒有改變任何東西。有任何想法嗎?如何在to_json中僅包含Mongoid引用的n-n中的一些屬性