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

Strange behaviour in a single line ruby sentence having a block and an if clause

I don't know why these two pieces of code behave different in Ruby 1.8.7 since one seems to be the single line version of the other. The first piece of code (it works as it should): if @type.present? type = @type orders =…
dguti
  • 1
0
votes
2 answers

Squeel iterating through an array with OR in Where block

I have the following query in Squeel: languages = where{ (name == 'English') | (name == 'Spanish') | (name == 'German') | (name == 'French') | ... } Which works fine but I was wodering if there was a way to iterate through an array with…
kakubei
  • 5,321
  • 4
  • 44
  • 66
0
votes
1 answer

Rails queries that consist of counts on associations, preferably with scopes

I've been making a search page for my service, and it includes several association based search parameters, I can think of a few messy long sql mess, but would prefer some cleaner approaches, as a sample, class Person < ActiveRecord::Base has_many…
Saifis
  • 2,197
  • 1
  • 22
  • 36
0
votes
0 answers

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 := DATEDIFF(end_at,@end) FROM PERIODS WHERE (@end > start_at…
0
votes
1 answer

Ruby Gem Squeel, how to write self join

I'm trying to write the following query using the ruby gem Squeel SELECT COUNT(*) FROM( SELECT a.end_at AS START, Min(b.start_at) AS END FROM periods AS a JOIN periods AS b ON b.season_id IN (1,2,3) AND a.end_at <= b.start_at WHERE…
0
votes
1 answer

Rails 3: Polymorphic conditioned query

I've got the following models: class Notification < ActiveRecord::Base belongs_to :notificatable, polymorphic: true end class BounceEmailNotification < ActiveRecord::Bas has_one :notification, :as => :notificatable, :dependent =>…
sauronnikko
  • 4,665
  • 5
  • 31
  • 47
0
votes
1 answer

Why is this Ruby Squeel (PostgreSQL) call returning nil, when it's clearly not?

I have a search page that allows a user to search for athletes based on criteria such as GPA and sport stats. When only one search filter is used, the PostgreSQL returns the correct answer. When more than one search filter is used, it will work ONLY…
trevorhinesley
  • 845
  • 1
  • 10
  • 36
0
votes
1 answer

Ranking results with complex conditions using Rails and Squeel

I'm probably doing something silly here - and I'm open to other ways of doing - but I'm trying to order my results set based on a computed field: Client.select{['clients.*', (cast((surname == matching_surname).as int) * 10 + …
erroric
  • 991
  • 1
  • 11
  • 22
0
votes
1 answer

Multiple joins to the same model using multiple belongs_to associations

I have a class Agreement that has two belongs_to associations to a Member class - referenced as primary and secondary: class Agreement < ActiveRecord::Base belongs_to :primary, class_name: 'Member' belongs_to :secondary, class_name: 'Member' …
erroric
  • 991
  • 1
  • 11
  • 22
0
votes
1 answer

How do I include the joined record in the result using squeel

st = 'pen' ak = '123123' agreements = Client.where{authentication_key == ak}.first.agreements products = Product.joins{agreements}.where{agreements.id.in(a) & (short_description.like(st) | long_description.like( st))} I am trying with the above but…
Boti
  • 3,275
  • 1
  • 29
  • 54
0
votes
1 answer

ruby date.month in words inside a squeel search

I'm using squeel, and I have a search method in my Event.rb model, which receives a parameter(string) from a text_field input def self.search(search) if search self.where{date.month.strftime("%B").matches("%#{search}%")} else find(:all) …
Daniel Romero
  • 1,581
  • 1
  • 20
  • 33
0
votes
2 answers

Rails AR + Mysql - Excluding movie genres doesn't work as expected

Let's say I have a movie database with genres and I would like to show all movies excluding some specific genres. I have associations all set up and working just fine. So to do this, i came across the gem named Squeel and wrote this piece of…
Vitali
  • 690
  • 9
  • 29
0
votes
2 answers

Representation of NOT IN combinations

I would like to use squeel in order to build query like: SELECT * from `table` WHERE (`field1`, `field2`) NOT IN ( (1,"value_a"), (2,"value_b"), (3,"value_a"), ... ) I want to know if there is any way to compare multiple fields with an…
Krule
  • 6,468
  • 3
  • 34
  • 56
0
votes
1 answer

Converting SQL into Arel or Squeel

tl;dr How to convert below SQL to Arel(or whatever is considered standard in Rails) @toplist = ActiveRecord::Base.connection.execute( 'select ci.crash_info_id, count(distinct(user_guid))[Occurences], c.md5 from crashes…
Jack Juiceson
  • 830
  • 4
  • 12
  • 24
0
votes
1 answer

Custom filter/scope based on project model

I'll try to be brief, but some detail is required. I'm trying to prototype a rewrite (in Rails) of a custom project management system. The primary purpose is to help companies who are relocating or expanding in Alabama to recruit, screen, and hire…
appleII717
  • 328
  • 3
  • 12
1 2 3
8
9