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
3
votes
2 answers

Composing one Gemfile from multiple others

I'm splitting a large application into multiple smaller ones. When doing this I realized that by creating a Gemfile.global and including it in both my main and sub applications I could clean up all of my Gemfiles. For example, all of my deployment…
Chris Keele
  • 3,364
  • 3
  • 30
  • 52
3
votes
1 answer

Wrong number of arguments when using Squeel

First, I do simple squeel testing in the Rails console. User.where{name == "abc"} There is no problem for new-created Ruby project User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."name" = 'abc' => [] However, when I apply it on my…
Vincent
  • 33
  • 4
3
votes
1 answer

Rails + Squeel Query Issue

Completely stuck on this and could use some help! I'm having users input certain preferences and then showing each user a set of results based on those preferences. There is a HABTM relationship between users and these preferences: User.rb has_many…
abhir
  • 1,059
  • 1
  • 9
  • 25
3
votes
1 answer

Is it possible to generate SQL `OR` clauses by using scope methods?

I am using Ruby on Rails 3.2.2 and the Squeel gem. I would like to know if there is a way to use more that one scope method so to generate SQL queries with OR clauses related to those scope method SQL conditions. That is, I have: class Article <…
Backo
  • 18,291
  • 27
  • 103
  • 170
3
votes
2 answers

Is it possible to "add" SQL clauses related to a `scope` method in a `where` method / clause?

I am using Ruby on Rails 3.2.2 and I am experimenting the Squeel gem. I would like to know if (in some way, by using the Squeel gem or not) it is possible to "add" SQL clauses related to a scope method "directly" in a where clause. That is, I…
user502052
  • 14,803
  • 30
  • 109
  • 188
2
votes
1 answer

ruby on rails 3 - advanced searches using gems

I have a User model with columns for Local, Skype, and Phone (boolean, 't' or 'f') and Gender (string, 'Male' or 'Female'). Each user can have many skills in the associated SkillMap model which has the skill_id and direction (string, either "Teach"…
joshblour
  • 1,024
  • 10
  • 19
2
votes
0 answers

Custom query with Squeel on equality of two attributes to ordered pairs

I'm having difficulty writing a query, whether in SQL or not, but I'd like to be able to write it in ruby using the gem Squeel. Basically, I have a class: class Article < ActiveRecord::Base belongs_to :genre belongs_to :publisher ... end I…
2
votes
1 answer

What is the syntax for referring to named scopes within Squeel?

Is there a way, using Squeel, to refer to already existing scopes? Consider the following: scope :continuous, where{ job_type_id == 1 } scope :standard, where{ job_type_id == 2 } scope :active, where{ (job_status_id == 2) & ((job_type_id == 1) |…
Daniel Vandersluis
  • 91,582
  • 23
  • 169
  • 153
2
votes
1 answer

Migrating from MetaWhere to Squeel and away from using symbols

I have an application where I want to migrate from MetaWhere to Squeel in preparation for an upgrade to Rails 3.1. This has been mostly a simple process but I have one case that causes me a bit of problems. The problem is that I have both the field…
HakonB
  • 6,977
  • 1
  • 26
  • 27
2
votes
0 answers

Rails left outer join on polymorphic association

I'm using the PublicActivity gem. I'm trying to eager load the associated activities for a group of users. I've set up the 'activist' association per their documentation in my user class, which defines this: def activist has_many…
swraife
  • 93
  • 2
  • 5
2
votes
0 answers

N+1 issue with rails partial

I have a Booking model , associated with Availability > Facility > Venue I have a page in my view which renders all bookings for a given venue and it's causing a huge N+1 query. Controller Action: def summary @venue = Venue.find…
Batman
  • 5,563
  • 18
  • 79
  • 155
2
votes
2 answers

Querying an indirect relationship

I have an app that has Users, Libraries and Books. Users have many Libraries. Libraries have many Users and Books. But Users and Books do not have a direct relationship. Users can only borrow Books from Libraries. I'm stuck trying to get the…
zapatos
  • 285
  • 4
  • 12
2
votes
0 answers

ActiveRecord / Arel: How to query self joined table (from has_many relation)?

I'm trying to convert some code from Squeel to ActiveRecord / Arel. The models looks like this: class Contract < ActiveRecord::Base belongs_to :institution belongs_to :issuer has_many :related_contracts, :through => :issuer, :source =>…
rwb
  • 4,309
  • 8
  • 36
  • 59
2
votes
1 answer

How to make a query in Postgres to group records by month they were created? (:created_at datetime column)

I have this Ruby code: def visits_chart_data(domain) last_12_months.collect do |month| { created_at: month, count: domain.visits.created_on_month(month).count } end end def last_12_months (0..11).to_a.reverse.collect{ |month_offset|…
Serge Vinogradoff
  • 2,262
  • 4
  • 26
  • 42
2
votes
1 answer

ruby - evalulate code returned from another method

ruby 2 and rails 4 Consider this chunk of code: Post.where{ (created_by == user) & ( (group_id.in [1,2,3,4]) | (event_id.in [5,6,7,8]) ) } Which works fine on its own. What I would like to do is take (group_id.in [1,2,3,4]) |…
Michael
  • 3,568
  • 3
  • 37
  • 50
1
2
3
8 9