Hello Guys,
In one scenario of my project, need to show all address with zipcode(stored as text field) sorting. It's good to make sort in db level as this will have better performance when comparing with ruby block.
in ../models/address.rb
This query will provide all customer address with zipcode in ascending order.
Thanks!!
Cheers up with Coding!!
In one scenario of my project, need to show all address with zipcode(stored as text field) sorting. It's good to make sort in db level as this will have better performance when comparing with ruby block.
in ../models/address.rb
def with_zipcode
Address.where(customer_id: 1).order('cast(zipcode as double precision)')
end
This query will provide all customer address with zipcode in ascending order.
Thanks!!
Cheers up with Coding!!
No comments:
Post a Comment