0

楷模:

class User
  include Mongoid::Document

  embeds_many :user_topics
end


class UserTopic
  include Mongoid::Document

  embedded_in :user
  embeds_many :user_topic_examples
end

class UserTopicExample
  include Mongoid::Document

  embedded_in :user_topic
end

如何获取属于特定用户的所有 user_topic_examples:

user.user_topic_examples

或者

user.user_topics.user_topic_examples

谢谢。

4

1 回答 1

1

这很简单:已更新

def user_topic_examples
  user_topics.inject([]) {|result, ut| result + ut.user_topics_examples }
end
于 2012-05-15T12:56:42.983 回答