mercredi 23 septembre 2015

Reducing an if statement to generate a mongoid query

I have the code below and I would like to know if it possible to reduce the code.

bank_accounts = self.client_bank_account_id.nil? ? self.client.bank_accounts : self.client.bank_accounts.where(_id: self.client_bank_account_id)

I only need the where call when client_bank_account_id is not nil.

Aucun commentaire:

Enregistrer un commentaire