mercredi 29 mars 2017

Rails: Adding scope in a model using column values of same model in where clause

I am new to rails. I am trying to create a scope using where clause. In that where clause i want to use column values of same model. But i don't know the correct way of doing that. Please help me out. Here's the code snippet:

attr_accessible :booked_qty,
                :cancelled_qty,
                :quantity_shipped

This is the scope that i am trying to create:

scope :shipped_qty_less_than_max_tolerance_qty, where("quantity_shipped < ?",self.booked_qty-self.cancelled_qty)

So what's the best way to write this scope? Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire