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
1
vote
1 answer

issue updating squeel with active admin, polyamorous, activerecord

I've got a project that is a couple of years old (rails 4) that I'm trying to update (all for the sake of active admin's datetime select not working) -- when I comment out the need to update squeel it all updates fine; but if I uncomment out squeel…
grimmwerks
  • 491
  • 1
  • 6
  • 21
1
vote
1 answer

Squeel subquery

I am trying to use a subquery to select the latest status of some records. I have the following query in SQL which I'd like to recreate in Rails using the squeel gem: SELECT * FROM changerequests c JOIN (SELECT changerequest_id, …
thenapking
  • 135
  • 14
1
vote
1 answer

Can't access SQL column aliases in Rails 4.1

After upgrading my rails app from 3.2 to 4.1.13 one of my queries doesn't seem to be making aliased columns available to ActiveRecord (I think). If I run .to_sql and query using that SQL I can clearly see the aliased columns are being returned but…
andyrue
  • 903
  • 10
  • 24
1
vote
1 answer

Trying to filter datetime fields based on time only

I'm having some trouble figuring out how to build a scope for a specific type of query I'm trying to do. Basically I have an Availabilities model which has a start_time and end_time datetime columns. I have a start and end time dropdown in my view…
Batman
  • 5,563
  • 18
  • 79
  • 155
1
vote
2 answers

Using scopes for search queries

I'm working on improving my search functionality in my app by using models. This is what I've been using so far: searchController#index: def index # Enable display of results page on direct access with no params return false if…
Batman
  • 5,563
  • 18
  • 79
  • 155
1
vote
4 answers

Get objects from sql which have no associated objects with specific field value

I have Job and Feedback models. They are associated like this: Job has_many :feedbacks Feedback belongs_to :job I'm trying to make a query to get jobs which have NO feedbacks with feedback.user_id == job.client_id
1
vote
1 answer

Select objects where all children have no grandchildren

I have the following three-level hierarchy of models: class Parent < AR::Base has_many :children end class Child < AR::Base has_many :grandchildren belongs_to :parent attr_accessible :my_number end class Grandchild < AR::Base belongs_to…
Chowlett
  • 45,935
  • 20
  • 116
  • 150
1
vote
1 answer

How to use Squeel to make innested query?

I'd like to build a query builder using squeel, here is how I did: Parent class: module ModelFilters class Base def initialize(user) @user = user end def build(method_name) head.where { my { send(method_name) } } end …
Rowandish
  • 2,655
  • 3
  • 31
  • 52
1
vote
1 answer

RoR/Squeel - How do I use Squeel::Nodes::Join/Predicates?

I just recently inherited a project where the previous developer used Squeel. I've been studying Squeel for the past day now and know a bit about how to use it from what I could find online. The basic use of it is simple enough. What I haven't been…
Isaac
  • 2,246
  • 5
  • 21
  • 34
1
vote
1 answer

Ruby Squeel library deprecation of core extensions

I started maintaining a big app with tons of Squeel queries. The latest Squeel version (>1.1) is deprecating code extensions: DEPRECATION WARNING: Core extensions are deprecated and will be removed in Squeel 2.0. Is there an easy way to grep for…
MegaTux
  • 1,591
  • 21
  • 26
1
vote
2 answers

Rails - JOIN clause doesn't include row with null Foreign Key

Let's say I have this data (notice the null author_id in third book): Authors ------------------------- id | name ------------------------- 1 | Susan Collins 2 | Steven Meyer ------------------------- …
hrsetyono
  • 4,474
  • 13
  • 46
  • 80
1
vote
2 answers

ActiveRecord conditionals for variable existence inside a where block

I had this bit of code using Squeel which worked perfectly: .where { [ entry[:imdb].presence && imdb == entry[:imdb], entry[:asin].presence && asin == entry[:asin], entry[:upc].presence && dvd_upc.upc == entry[:upc] …
kakubei
  • 5,321
  • 4
  • 44
  • 66
1
vote
0 answers

Rails 4: Query with optional joins

I've got the following classes. They work the same way: a person can be a guardian, employee and student in many schools, and they also have one user. class User < ActiveRecord::Base belongs_to :person end class Person < ActiveRecord::Base …
sauronnikko
  • 4,665
  • 5
  • 31
  • 47
1
vote
0 answers

ActiveRecord, Squeel: Getting objects without parent associations

I have: class ThingsCollection < ActiveRecord::Base has_and_belongs_to_many :things, uniq: true end class Thing < ActiveRecord::Base has_and_belongs_to_many :things_collections, uniq: true end I want to get Things which don't have any…
1
vote
0 answers

How can this SQL subquery be expressed using Squeel/ActiveRecord?

I'm having a bit of brain fade today and can't figure out how I should express this SQL query correctly using ActiveRecord/Squeel/ARel: SELECT `d1`.* FROM `domain_names` d1 WHERE `d1`.`created_at` = ( SELECT MAX(`d2`.`created_at`) FROM…
tristanm
  • 3,337
  • 2
  • 27
  • 40
1 2 3
8 9