mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Allow User#default_card to work with eager-loading
This commit is contained in:
@@ -125,7 +125,12 @@ module Spree
|
||||
end
|
||||
|
||||
def default_card
|
||||
credit_cards.where(is_default: true).first
|
||||
# Don't re-fetch associated cards from the DB if they're already eager-loaded
|
||||
if credit_cards.loaded?
|
||||
credit_cards.to_a.find(&:is_default)
|
||||
else
|
||||
credit_cards.where(is_default: true).first
|
||||
end
|
||||
end
|
||||
|
||||
# Checks whether the specified user is a superadmin, with full control of the
|
||||
|
||||
Reference in New Issue
Block a user