屬性我有一個User
模型中嵌入一個Profile
:如何基於嵌入式模型申報範圍與Mongoid
# app/models/user.rb
class User
embeds_one :profile
end
# app/models/profile.rb
class Profile
embedded_in :user, inverse_of: :profile
field :age, type: integer
end
現在我想在User
申報範圍,可以列出其profile.age
爲所有用戶> 18
。
不要ü要在範圍或全部去取的唯一相關B的? – krishnar
你寫的第一件事embeds_one這意味着A將只有一個B,那麼爲什麼年齡> 18?其次:如果你想不管的的獲取所有B,則不要使用embeds_one – krishnar
令用戶是和Profile是B和剖面模型包含年齡字段 我想獲取所有的年齡大於18 – manojchowdary27