0
votes
0answers
66 views

Complex SQL query Rails

Lesson.joins(:custom_attributes).where("custom_attributes.attribute_name_id = 103 AND cast(custom_attributes.value as float) BETWEEN 0 AND 61").where("custom_attributes.attribute_name_id = 103 AND ...
0
votes
0answers
36 views

scope to order on polymorphic belongs to association attribute

i got a polymorphic belongs to association on a model. i want a scope that orders my models on an associated column. class Notifier < ActiveRecord::Base belongs_to :source, :polymorphic => ...
0
votes
0answers
46 views

Rails select by group with Postgresql?

I have a model named Program, which has 'directory_id'、'id'、'user_id' columns, I want to select all the programs group by directory: @programs = Program.select("programs.directory_id, programs.id, ...
0
votes
2answers
119 views

PostgreSQL query returning multiple rows instead of one

I have two tables: user and projects, with a one-to-many relationship between two. projects table has field status with project statuses of the user. status can be one of: launched, confirm, ...
1
vote
2answers
180 views

Get “latest” row after GROUP BY over multiple tables

I'd preferably like to first query listed below and just group by stories.id, but I get the following error: ERROR: column "u.first_name" must appear in the GROUP BY clause or be used in an ...
2
votes
5answers
233 views

how to select/find the table data along with the latest associated (many to many) data

I have following relation in my tables item.rb has_one :item_shipping_detail item_shipping_detail.rb belongs_to :item has_many :shipping_statuses status.rb belongs_to :item_shipping_detail ...
2
votes
1answer
283 views

How to combine these two PostgreSQL statements into one for Rails 3 application?

I have two PostgreSQL statements that I would like to combine in my RoR application. The first SQL statement returns a link where the link contains two specific tag_ids. SELECT link_id, count(*) as ...
0
votes
1answer
233 views

What is causing PGError: ERROR: there is no parameter $1 in my Rails app

I started getting this error on edit/show of a Rank object. I've never seen it before and am not sure how to resolve it. Any input?
1
vote
2answers
145 views

How to find posts with multiple tags

I have a very simple tag model on Rails with postgresql: class Tag < ActiveRecord::Base has_many :taggings has_many :posts, :through => :taggings, :source => :tagged, ...
0
votes
3answers
365 views

How do you select data from PostgreSQL database, but if no data is present for a given day, then return 0?

I have the following query: SELECT created_at::DATE, count (*) FROM messages WHERE city = 'los angeles' GROUP BY created_at::DATE Which works great. The challenge is that if there are ...