I’m using Active Record to send a few queries to a postgres database. I have a User model, a Business model and a joiner named UserBiz. The queries I mentioned go through the entire UserBiz collection and then filter out the businesses that match user provided categories and searches. These “work” but the problem is when I threw a quarter
Tag: rails-activerecord
Rails – deeply nested joins with ActiveRecord
I occasionally need to do a join in my app that goes across multiple tables, but haven’t quite figured out how to do this for more than 3 tables: Currently I’m ready to go: What I would like to do now is to join every consumer that belongs to an OrderListItem. However, when I try the following: I get the
Total value of warehouse active record
I have the object Tool and I need to calculate the cost of all the Tools in the warehouse. I can sum the column price Tool.sum(:price) but i need to sum (quantity * price) of all the table Tools. Thanks in advance. Answer Check out the example listed for ActiveRecord::Calculations#calculate. You can do the following:
Where with OR condition for the same column in Rails
I’m trying to retrieve all records that have expired_at as nil and expired_at greater than the current time. I’ve tried this: But that is only returning me the records expired_at greater than DateTime.now. Why is the nil being neglected? Answer Your current query checks that expired_at is equal to null (via = NULL) which will not evaluate to true. Instead,
Rails Postgres query, selecting only items that appear in all search params with associations
I’m looking to create a Postgres query based on a few user select params. A user will select a shop and a start and end year. Once submitted I’m would only like to display average prices of items if …
Raills: Get SQL generated by delete_all
I’m not particularly familiar with Ruby on Rails, but I’m troubleshooting an issue we’re experiencing with a rake job that is supposed to be cleaning database tables. The tables grow very large very …