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

How to use joins in Rails with squeel

How to use joins or other ways to let me use the where query to compare other conditions in another model? Model relation class SonyAlarmLog < ActiveRecord::Base belongs_to :sony_alarm_test class SonyAlarmTest < ActiveRecord::Base has_many…
user3675188
  • 7,271
  • 11
  • 40
  • 76
0
votes
1 answer

Rails, ActiveRecord, Squeel: Check if value exists in array

I have 2 tables: 'Actor' & 'Role'. Each table has a column named 'ethnicity'. An Actor can only have 1 ethnicity, but a Role can have 1 or more ethnicities. So for example, let's say I want to find all the roles that match Actor1's ethnicity…
user1341808
  • 249
  • 4
  • 7
  • 18
0
votes
1 answer

Squeel working in Rails Console but not in Controller. Error: undefined method `method' for nil:NilClass

I'm using Squeel, and I have an odd problem. The following line runs just fine in Rails Console, but gives an error when run in the model's controller! Issue.joins{property.users}.where{property.users.id == 1} Issue belongs_to Property, and Property…
Armin
  • 1,150
  • 8
  • 24
0
votes
0 answers

Rails 4 ActiveRecord::Relation ArgumentError just doesn't make sense

This is a rather simple Rails 4 situation. Model Intranet has_many activities. Activities exists with sufficient records for several intranets. Current_intranet.activities.size returns 69 records. However, whenever I try to access any of the…
0
votes
1 answer

Rails, squeel - loop inside 'where'

I want to use some sort of loop or iterator inside where statement like Product.where{ array.each do |e| (id >= e[0]) & (id <= e[1]) end } Is something like this possible? In reality query is much more complicated, and I don't want to post whole…
Artyom Tsoy
  • 2,238
  • 1
  • 13
  • 18
0
votes
0 answers

Squeel query cannot be chained with pg_search query in Ruby on Rails

I would like to execute the following code to perform a search in my controller: experts_controller.erb @users = User.text_search(params[:query]).has_skill_categories(params[:skills]).has_marketing_assets(params[:marketing_platforms]) When I run…
miggitty
  • 47
  • 2
  • 9
0
votes
2 answers

Re-writing a SQL Query using Active Record or the Squeel Gem in Ruby on Rails 4

I am having a lot of problems rewriting this SQL Query in Squeel or straight Active Record using Ruby on Rails 4. All 3 numbers in the query need to be passed to the query before execution. The SQL Query is below. SELECT "users".* FROM "users" …
miggitty
  • 47
  • 2
  • 9
0
votes
1 answer

what default value of a date should be given that it returns all the record if user has not entered date in squeel

I am using a squeel gem and I have a scenario that when user does not enter employee joining date then all the records should be returned else return record on the basis of employees joining date. my query is loke this : date =…
user1183194
  • 137
  • 1
  • 2
  • 14
0
votes
1 answer

ActiveRecords Join with conditions: how to join on the same table with different sets of conditions using squeel sifters?

I have two activerecords classes, User and UserSkill. UserSkill has a squeel sifter, as shown below: class User < ActiveRecord::Base has_many :user_skills end and class UserSkill < ActiveRecord::Base belongs_to :user belongs_to :skill …
mulus
  • 475
  • 1
  • 4
  • 7
0
votes
1 answer

Where chains or similar in Rails to narrow results

How do you narrow results from a table in Rails? I'm using Rails 4.0.2 and PostgreSQL and can do users = User.where(:flag1).where(:flag2 => nil) but not users = User.where(:flag1).where(:flag2 => nil).where(:flag3 => nil) to…
0
votes
0 answers

Select products, that have all of the parameters in column

I have a Product model and ProductParams, where I store product ids, column with some additional parameters(param) and param type. It will look like that: id | type | param | | 1 | color | blue 1 | type | hard 2 | color | blue 2 |…
Artyom Tsoy
  • 2,238
  • 1
  • 13
  • 18
0
votes
0 answers

Has many :through a Polymorphic association not aliasing type column with Squeel 1.1.1

I've got a few classes: class Membership < ActiveRecord::Base belongs_to :group belongs_to :member, polymorphic: true end class User < ActiveRecord::Base has_many :memberships, as: :member, dependent: :destroy has_many :groups, through:…
0
votes
0 answers

Ordering nested has_many :through by count of associations

I'm trying to order Tags by order of the descending frequency of their association with Users of a specific Group. (ActiveRecord & Rails 3.2 - I also have Squeel installed if that helps!) Users have Tags, Groups have Users. Groups thus have Tags…
djoll
  • 1,139
  • 1
  • 12
  • 31
0
votes
1 answer

ActiveRecord Use An array of arrays As Parameters

I would like to form the following query: SELECT tracked_points.* FROM tracked_points WHERE (id = 87 AND zone_id = 457) OR (id = 88 AND zone_id = 457) My input to the function will be a nested array of [id, zone_id], something like: [[87, 457],…
Tyler DeWitt
  • 23,366
  • 38
  • 119
  • 196
0
votes
1 answer

Fetch and count records by Date

I have to make a query to fetch and then count all records with created_at, by Date in the time zone: def total_by_date(my_date) where{created_at <= my_date}.count end created_at is stored as timestamp in UTC in PostgreSQL, but my_date is a…
Leo Burt
  • 109
  • 1
  • 6
1 2 3
8 9