Questions tagged [squeel]

Squeel is a "database toolkit" for the Ruby programming language. It extends Active Record with a handy block-based syntax.

Squeel is a "database toolkit" for the Ruby programming language.

It extends Active Record with a handy block-based syntax.

Squeel is available via rubygems.org, the code is available at github.

Examples canm be found at the project website is http://erniemiller.org/projects/squeel

Sequel was primarily developed by Ernie Miller. It is not maintained by him anymore.

Don't mix up squeel with sequel.

128 questions
2
votes
1 answer

ActiveRecord::QueryMethods::WhereChain

I'm using squeel and I'm getting a ActiveRecord::QueryMethods::WhereChain returned from a query rather than an ActiveRecord::AssociationRelation. Query: game.golfers.where{competitors.swing_golfer IS DISTINCT FROM TRUE} Query that returns…
Tyler DeWitt
  • 23,366
  • 38
  • 119
  • 196
2
votes
0 answers

Squeel Select distinct records after join

I have a model with a has_many relationship to widgets and I'm trying to retrieve a unique list of users who have widgets (some have more than 1 widget). User has_many :widgets ## join the user table User.joins{widgets}.where{ widgets.kind.eq…
Paul
  • 2,021
  • 5
  • 22
  • 33
2
votes
2 answers

INSERTs and UPDATEs in ruby/rails using PostgreSQL functions

I'm using activerecord-postgis-adapter and squeel in a geo oriented application. Fetching data using various queries based on find and where is working fine and squeel allows me to use PostgreSQL/PostGIS functions to query based on spatial functions…
averas
  • 545
  • 1
  • 6
  • 15
2
votes
2 answers

Advanced activerecord query where association with a limit

I'm trying to do a more advanced query with activerecord and can't figure out the best way to write it. Hopefully this makes sense... My POSTGRES/rails app has models: Company has_many :employees Employee has_many :evaluations Evaluations has…
Joel Grannas
  • 2,016
  • 2
  • 24
  • 46
2
votes
2 answers

Metaprogram Squeel to search on keypaths

The question I'm trying to wrap my head around arel and squeel, but I feel like I lack the vocabulary to ask Google what I'm looking for. TL;DR: Does anyone know how to mimic Squeel's Model.where{related.objects.field.matches string} syntax out of…
Chris Keele
  • 3,364
  • 3
  • 30
  • 52
2
votes
2 answers

Squeel syntax for field = value OR field IS NULL in a loop

I'm trying to recreate the following syntax using squeel by using a loop: WHERE season = "value" OR season IS NULL I was able to get this far: where do ((season == entry["season"]) | (season == nil)) & ((episode == entry["episode"]) | (episode…
kakubei
  • 5,321
  • 4
  • 44
  • 66
2
votes
2 answers

Squeel evaluating a string as a keypath for joins

Here's what I'd really like to do: Outage.joins{eval "unit.plant"} I'm going to have a string that represents a squeel keypath. I'd like to send this string into a join statement. But here's what I get as an error: #: unknown…
barancw
  • 888
  • 9
  • 18
2
votes
1 answer

Performing multiple joins on the same association with Squeel

In my application, I have to models: Workflow and Step; steps belongs_to workflow and a workflow has_many steps. Steps have an index and a boolean status ('completed'). I want to retrieve workflows whose step 1 is completed and step 2 is not, i.e.…
Dom
  • 31
  • 2
2
votes
1 answer

How do I handle the where conditions dynamically in squeel?

From this input: {'hearing' => 1} I need to generate this query Score.joins(:target_disability).where{ (target_disabilities.name == 'hearing') & (round(total_score) >= 1) } From this input is {'hearing' => 1, 'mobility' => 2}, I need to generate…
Boti
  • 3,275
  • 1
  • 29
  • 54
1
vote
1 answer

Using NOW() in a select with Squeel

I want to get the average of the difference between the current time and a datetime value in the database with Squeel: Car.select{average(NOW() - created_at)} Which tries to take "NOW" as a column in the database: ActiveRecord::StatementInvalid:…
Cristian
  • 5,877
  • 6
  • 46
  • 55
1
vote
2 answers

valid_scope_name?': private method `warn' called for nil:NilClass (NoMethodError) exception while updating to active record 3.1 (rails)

The thing is there is a rubygem which adds some syntactic sugar to RoR ActiveRecord for defining filters and orders. We were using meta_where, then switched to squeel to get rails 3 support. The thing is that everything worked fine with ActiveRecord…
Neithan
  • 11
  • 2
1
vote
1 answer

Had to re-write a DB Query for Rails 6 due to Squeel gem: Error: undefined method `call' for #

I recently had to re-write an APP called CtrlPanel which I have all done and working well. (Thanks to several users on StackOverflow for helping with that!) I am now onto the second app I have to rewrite called Emissions Gateway. Just like…
Scott Milella
  • 468
  • 5
  • 10
1
vote
1 answer

How to specify this query using Squeel?

Suppose I have a model: class Question < ActiveRecord::Base attr_accessible :title # it has title attribute has_many :pictures end I want to define a scope query called completed that: Returns all questions whose: title is not empty…
sivabudh
  • 31,807
  • 63
  • 162
  • 228
1
vote
1 answer

Coalesce with baby_squeel / arel in Rails

I am trying to write a rather complicated query using baby_squeel. The query requires the use of the coalesce SQL function. coalesce is used as an example a couple of times on the baby_squeel home page but when I try to use it in a query I get a no…
JosephGage
  • 79
  • 2
  • 9
1 2
3
8 9