Questions tagged [arel]

Arel is a Relational Algebra for Ruby. It simplifies the generation complex of SQL queries and it adapts to various RDBMS systems.

Arel is a Relational Algebra for . It simplifies the generation complex of SQL queries and it adapts to various RDBMS systems. More info on project's page. The Arel gem is supported in framework versions 3.0 and up, however for the 2nd version of Rails the fake_arel gem shell be used.

723 questions
0
votes
1 answer

Are those two queries the same in rails 3.2.12?

We need to retrieve logs for customer comm record in our rails app. The condition in plain english is logs for customer_comm_record based on: #1. the sales_id in customer comm record's customers is equal to current user id #2. the sales_id in…
user938363
  • 9,990
  • 38
  • 137
  • 303
0
votes
2 answers

Rails/Arel User.where(:id => .user_id)

Hey I'm just getting back into rails and I've forgotten a lot of the stuff needed to work with some associations. The Problem: I have two tables, Customer with fiels id and user_id and User with field id. I want to get an array of Users such that a…
aarona
  • 35,986
  • 41
  • 138
  • 186
0
votes
1 answer

Rails subquery / nested join on a many-to-many association

I have two models, Item and Tag, that have a many-to-many relationship through a model called ItemTag. I want the user to be able to find all items that have ALL of a given set of tags.tag_name. So, the tables look like…
J Plato
  • 888
  • 1
  • 8
  • 17
0
votes
1 answer

Rails, find results based on shared association using Active Record Query or AREL

I'm working on a rails project where I have a User, that has_many Teams through a Membership model. The User has a privacy setting which can be (public, private or protected) On the current user's homepage, I want to display all of the users who…
0
votes
1 answer

Trying to create a complex AR query that includes associations

I have a Story model that has a :category attribute. Story is also in a HABTM relationship with Tag. class Tag < ActiveRecord::Base has_and_belongs_to_many :stories, :uniq => true validates :name, :presence => true validates …
chuck w
  • 1,741
  • 2
  • 15
  • 34
0
votes
1 answer

How to use AREL eq() method in a where with joined data

I currently have this scope: class User has_many :inbox_messages, :through => :message_users do def unread published.where(:message_users => { :sender => false, :trash => false , :deleted =>…
Nerian
  • 15,901
  • 13
  • 66
  • 96
0
votes
1 answer

SQL Inner JOIN with query

I am trying to do something like this but I am not sure if you can do this with a inner join: SELECT "scores".* FROM "scores" INNER JOIN "games" ON "games"."id" = "scores"."games_id" WHERE "games"."date" >= '2013-02-11 19:30:11.799227'…
trev9065
  • 3,371
  • 4
  • 30
  • 45
0
votes
1 answer

Rails Nested / Multi-level AREL Query

I have 3 models: Tiersets has_many Tiers Tiers belongs_to Tierset has_and_belongs_to_many Features Feature has_and_belongs_to_many Tiers In Feature, I have a String column named Feature_Code that contains one of the following strings:…
tarunsachdeva
  • 453
  • 1
  • 4
  • 13
0
votes
1 answer

Rails 3, Cannot visit Arel::SelectManager

I have user model with :except_ids scope: scope :except_ids, ->(*ids) { where { id.not_in ids } } The problem is - I can't use it with another lazy queries. For example, if I call something like this: User.except_ids(User.except_ids(1,2)) I end up…
user2134949
0
votes
3 answers

How do I write a query in Active record for a model that has whos has_many is empty?

I have model Member which has many DuesPayments. I want a query for Members who didn't make their dues_payment in 2012. The field on DuesPayment is :for_year. Or in English - I want all members who don't have a record in the dues_payments table with…
pixelearth
  • 13,674
  • 10
  • 62
  • 110
0
votes
2 answers

ActiveRecord scope based on number of foreign keys

Given the canonical example: class Post < ActiveRecord::Base has_many :comments end class Comments < ActiveRecord::Base belongs_to :post end I would like to return a scope (i.e. ActiveRecord::Relation) of all the Posts that have X or fewer…
Thomas Nadin
  • 1,167
  • 10
  • 22
0
votes
1 answer

Table-less select using Arel

How would one write the following SQL query using only Arel functions? select array_to_string(array(select name from tags, taggings where tags.id=taggings.id), ', ') Caveat: This is an SQL fragment that is supposed to be part of a larger correlated…
Saurabh Nanda
  • 6,373
  • 5
  • 31
  • 60
0
votes
1 answer

Convert this SQL query to AREL (outer joins)

I'm trying to convert this query to AREL: SELECT users.* FROM users LEFT OUTER JOIN ( SELECT DISTINCT educations.user_id FROM educations INNER JOIN schools ON educations.school_id = schools.id WHERE schools.name =…
porkeypop
  • 324
  • 2
  • 11
0
votes
1 answer

How to search belongs_to association attributes

I have two entities Posts and Comments associated as follows class Post < ActiveRecord::Base attr_accessible :title, :msg has_many :comments end class Comment < ActiveRecord::Base attr_accessible :msg belongs_to :post scope :search,…
user1094976
0
votes
0 answers

How can I convert this SQL into ActiveRecord/Arel syntax?

I'm running into problems when I move this SQL around to different database adapters. I want to convert it into something more flexible. Here it is: Foo.includes([{ :group => :memberships }, :phone]). where('("memberships"."user_id" = ? AND…
Logan Serman
  • 29,447
  • 27
  • 102
  • 141