Search code examples
rubycurrencymoney-rails

Return results from money (ruby) with a comparison (e.g. items more than x)


Pretty simple one.

I want to do the following

Model.where("money_rate > ?", some_other_money_item)

Any ideas?

PG::UndefinedColumn: ERROR:  column "money_rate" does not exist
LINE 1: SELECT "jobs".* FROM "jobs"  WHERE (money_rate > '--- !ruby/...etc

Solution

  • Seems that you can only do a comparison using the base method, in the above case this would be money_rate_cents

    So:

    Model.where("money_rate_cents > ?", some_other_money_item_in_cents)
    

    Returns an array of items where the money attribute is higher.

    Will leave that in case someone else finds it useful. Or in case I'm missing something and you can do comparisons on the whole number.