Mongoid: How to load only some fields of an object you lazy load via reference?

前端 未结 2 656
忘掉有多难
忘掉有多难 2021-01-17 18:05

For performance reason, I use as often as possible the only() keyword when writing up a mongoid query in order to specify the fields I want to load.

The

2条回答
  •  逝去的感伤
    2021-01-17 18:25

    I think you need to denormalize here. First of all, read A Note on Denormalization.

    You can implement denormalization by self using mongoid events or use great mongoid_denormalize gem. It pretty straight and after implementing it you could use p.user_email or something in your queries.

提交回复
热议问题