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
是否可以在不使用此循环的情况下过滤所有作业?
有更好的方法来做到这一点吗?