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

Rails ActiveRecord::StatementInvalid: PG::Error: ERROR: missing FROM-clause entry for table

I've a complex ActiveRecord query that I'm building up with different scopes, depending on the user selection. I'm using 2 gems, which seems to be problematic together, but I cannot find who's the culprit between : Texticle (for Postgresql full…
xlash
  • 363
  • 1
  • 3
  • 16
9
votes
3 answers

How would you do this Rails sub-query using Squeel?

I want to restructure the query below using Squeel. I'd like to do this so that I can chain the operators in it and re-use the logic in the different parts of the query. User.find_by_sql("SELECT users.*, users.computed_metric, …
Peter Nixey
  • 16,187
  • 14
  • 79
  • 133
7
votes
1 answer

'on' option to joins in squeel

Is there a way to add "on" conditions to a joins in Squeel. If not, are there other alternate options to accomplish the same? If you want to override Rails default join mappings, you can do it using Arel on(). Is there an equivalent call in Squeel…
ssr
  • 71
  • 2
5
votes
3 answers

in `lambda': tried to create Proc object without a block (ArgumentError)

scope :for_user, (lambda {|user_id| a = Follow.follows(user_id); Question.where{user_id.in(a.select{followed_id})}}) Gives me: `lambda': tried to create Proc object without a block (ArgumentError) I've read several questions without being able to…
4
votes
3 answers

Scopes and associations not working

I'm trying to return records where the association is either present or not: I tried these scopes: class Booking < ActiveRecord::Base has_one :availability scope :with_availability, -> {where{availability.not_eq nil}} scope…
Batman
  • 5,563
  • 18
  • 79
  • 155
4
votes
5 answers

Optimize difficult query (possibly with squeel)

There is such code(using PublicActivity gem & Squeel) def index @activities = Activity.limit(20).order { created_at.desc } @one = @activities.where{trackable_type == 'Post'}.includes(trackable: [:author, :project]) @two =…
just so
  • 1,088
  • 2
  • 11
  • 23
4
votes
2 answers

Can you add clauses in a where block conditionally when using Squeel?

To start, I'm using Rails v3.2.9 with Squeel 1.0.13 and here's what I'm trying to do: I want to search for a client using any of three pieces of identifying information - name, date of birth (dob), and social insurance number (sin). The result set…
erroric
  • 991
  • 1
  • 11
  • 22
4
votes
1 answer

Using NOT with Squeel

Say I have a set of conditions: Person.where{(name =~ 'Ernie%') & (salary < 50000) | (name =~ 'Joe%') & (salary > 100000)} ...which will generate SQL as follows: SELECT "people".* FROM people WHERE ("people"."name" LIKE 'Ernie%' AND…
Codebeef
  • 43,508
  • 23
  • 86
  • 119
3
votes
1 answer

Nested query in squeel

Short version: How do I write this query in squeel? SELECT OneTable.*, my_count FROM OneTable JOIN ( SELECT DISTINCT one_id, count(*) AS my_count FROM AnotherTable GROUP BY one_id ) counts ON OneTable.id=counts.one_id Long version:…
dslh
  • 1,805
  • 14
  • 19
3
votes
2 answers

Squeel to execute outer join on Rails

I'm trying to find a way to create a simple outer join without too much hassle. I know I can do this manually by specifying an outer join, but I'm looking for a simple way. Therefore, I was taking a look at Squeel, which seems to be the new…
Spyros
  • 46,820
  • 25
  • 86
  • 129
3
votes
1 answer

Possible sql injection

I'm using squeel gem in my project, and I have code something like this : def self.search(query) return self.scoped if query.blank? self.joins(:supplier).where{lower(supplier.supplier_name).like_any(["%#{query}%"])} end My questions is…
Gandalf StormCrow
  • 25,788
  • 70
  • 174
  • 263
3
votes
1 answer

How to handle gem conflicts?

I am using two gems ie squeel and activeadmin and running bundler gives me issue ie: Bundler could not find compatible versions for gem "polyamorous": In Gemfile: activeadmin (>= 0) ruby depends on polyamorous (~> 0.5.0) ruby squeel…
Mohit Jain
  • 43,139
  • 57
  • 169
  • 274
3
votes
1 answer

Rails and PostgreSQL issue with Having

I am trying to retrieve a table from the following Action table: Columns :ID, Name, Status, Product_ID, User_ID and several other non relevant column for this issue. Every time a user want a product I create a record like this : Name = Want, Status…
Jeremy B
  • 911
  • 7
  • 20
3
votes
2 answers

Using NOT operator with Squeel?

How do I write a SQL query using Squeel? SELECT * FROM documents where (NOT document.deleted OR document.deleted IS NULL) I tried: Document.where { (-deleted) | (deleted == nil) } but get this error: NoMethodError: undefined method `|'…
mma
  • 33
  • 4
3
votes
2 answers

Squeel and rails... dynamic where clause

Using Squeel, in a rails app, I have a hash of conditions: {'trans' => 'manual'} which i eventually plan on moving into an array... so i can also have an operator assignment. [[field,operator,value][field,operator,value]] I want to use a Model…
Joel Grannas
  • 2,016
  • 2
  • 24
  • 46
1
2 3
8 9