1
vote
1answer
33 views

Make an IN statement using two attributes in Activerecord

I've been trying this for a while, and can't seem to get it right in Activerecord. Given an array of asset_id and asset_type pairs, query a class that has both those attributes, only where both ...
-1
votes
0answers
27 views

ruby on rails - SQL query how to COUNT children while also passing other attributes

So I have a matchups table (which has_many groups through groups_matchups) and a groups table (same deal). Matchups are supposed to have two groups, and groups can belong to many matchups. Also, ...
0
votes
3answers
61 views

Selecting record by a range of months

I have a table with a start_date and end_date for each row. end_date can by of a different year than the start date. I need to select all records that overlap an input months range. For example: ...
0
votes
1answer
14 views

Rails / SQL … better to access database once and store data in array?

The heart of my app is a multi-conditional comparison using an input array and parameters stored in a few database tables. I'm trying to make the process most efficient ... and I think this could ...
0
votes
1answer
20 views

Complex SQL converted to active record

I have been puzzling over the following query, and how it could be done using active record. select * from links where id in (select id from (select votable_id as id, count(votable_id) ...
0
votes
0answers
73 views

Sum returning null

I am having a problem with a Ruby SQL look up function: it always returns a null. Here is the terminal output: SELECT COUNT("point_store_items"."point_cost") FROM "point_store_items" INNER JOIN ...
0
votes
2answers
17 views

Rails seed.rb can't find table that exists in schema and SQL

Class is a reserved word, so I have changed the table name from class_assignment to cassignments to avoid any chance that that is the error causing it (despite me having class_instruction(s). I have ...
0
votes
0answers
27 views

I can't import SQL to database in Rails

To be organized I want to have a file db/seeds/countries.rb with: ActiveRecord::Base.connection.execute(IO.read("db/sql/countries_iso3166.sql")) And this file db/sql/countries_iso3166.sql has a SQL ...
0
votes
2answers
13 views

Rails 3 - How to do a find_all_by with a single exception (removing a single record from the resulting array)?

I have a case where I must use find_all_by; I have a cookie session hash which is limited in size (4kb), so instead of storing the records I need themselves, I'm storing just the IDs in an array. ...
0
votes
2answers
18 views

Rails Active record association by instance methods

I am trying to have (devise) users.rb be placed within a ClassInstruction.rb based on their userRole.rb (teacher or student). The models and schema are below, along with the error. It errors on ...
0
votes
0answers
22 views

Translate complex SQL query using SET to Arel or Squeel

How can I translate the given query using AREL or Squeel: SET @start = '2013-05-14'; SET @end = '2013-11-01'; SET @days = DATEDIFF(@end, @start); SET @UnusedDays = 0; SELECT @UnusedDays := ...
0
votes
1answer
35 views

Is there a better way to structure these database tables?

I'm struggling with the best way to design/query my db on a new Rails app. This is what I have in place right now: documents: title has_many :document_sections document_sections: belongs_to ...
0
votes
1answer
22 views

AND multiple JOIN statements in Rails

I have a table for users and roles. I'm using a has many through relationship. I am trying to create a query that will find users that have all of the roles in an array. ex. role_ids = [2, 4, 6] ...
0
votes
1answer
15 views

ruby on rails: multiple insertion SQLite3::SQLException: near “,”: syntax error:

I need to do a multiple insertion in the database.It shows me an error all the time Single insertion works perfect: CONN = ActiveRecord::Base.connection irb(main):271:0> ...
2
votes
4answers
85 views

Database design to store lottery information

I am designing a system where I am supposed to store different types of Lottery(results + tickets). Currently focusing on US Mega Millions and Singapore Pool Toto. They both have a similar format. ...

1 2 3 4 5 96
15 30 50 per page