class User
include Mongoid::Document
has_many :orders
has_one :payments
end
class Order
include Mongoid::Document
belongs_to :user
has_one :payment, dependent: :destroy, :autosave => true
end
class Payment
include Mongoid::Document
belongs_to :order
belongs_to :user
ebd
user_controller.rb
jobs
アクションについて:
def jobs
#
#
jobs = Order.where(:seller_id => current_user.id).order_by :created_at, :desc
@jobs = []
for j in jobs
if j.payment.preapproval_key != nil && j.payment.correlation_id != nil && j.payment.approved == true
@jobs << j
end
end
#
#
end
payment.preapproval_key != nil && payment.correlation_id != nil && payment.approved == true
このループを使用せずにすべてのジョブをフィルタリングすることは可能ですか?
これを行うためのより良い方法はありますか?