How to Determine if Rails Association is Eager Loaded?

前端 未结 7 1311
后悔当初
后悔当初 2021-01-30 16:02

Does anyone know a way to determine if a Rails association has been eager loaded?

My situation: I have a result set where sometimes one of the associations is eager l

7条回答
  •  暖寄归人
    2021-01-30 16:30

    Use .association(name).loaded? on a record.


    For Rails < 3.1 use loaded_foo?.

    (It is deprecated since Rails 3.1. See: https://github.com/rails/rails/issues/472.)

提交回复
热议问题