arel Questions
3
Solved
I have this use case where I get the symbolized deep associations from a certain model, and I have to perform certain queries that involve using outer joins. How can one do it WITHOUT resorting to ...
Depoliti asked 22/2, 2013 at 17:12
3
Consider the following code fragment:
def sql
billing_requests
.project(billing_requests[Arel.star])
.where(
filter_by_day
.and(filter_by_merchant)
.and(filter_by_operator_name)
)
.to_sql
...
Squaw asked 20/6, 2015 at 7:0
2
Solved
I have a User model that has first_name and last_name attributes. Using Arel I would like to perform a full name search using CONCAT. I've read the post at How do I use functions like CONCAT(), etc...
Catarinacatarrh asked 6/12, 2013 at 19:8
1
Consider the following query:
SELECT DATE_TRUNC('hour', date_range)
FROM GENERATE_SERIES(:start_date, :end_date, :interval) as date_range
Is it possible to use GENERATE_SERIES(...) as a table (...
Jemadar asked 8/12, 2014 at 13:50
3
Solved
Using Arel in Rails - I'm looking for a way of creating an ActiveRecord::Relation that effectively results in SELECT * FROM table, which I can still manipulate further.
For example, I have a model...
Eichelberger asked 8/4, 2011 at 13:38
2
Solved
I am trying to convert a "raw" PostGIS SQL query into a Rails ActiveRecord query. My goal is to convert two sequential ActiveRecord queries (each taking ~1ms) into a single ActiveRecord query takin...
Beall asked 16/1, 2015 at 22:44
1
Solved
I can run a query in two different ways to return a Relation.
When I interrogate the size of the Relation one query gives a Fixnum as expected the other gives a Hash which is a hash of each value ...
Capitate asked 15/1, 2015 at 2:59
0
(This is a more specified version of the question that I asked previously but that has not received any answers; I hope it's not against SO’s rules)
Given that I have a Rails 4 app that has a Spon...
Septemberseptembrist asked 29/12, 2014 at 1:16
4
Solved
I need to insert a array of emails as different records into my contacts table. How can this be done.
Eg: @email = ["[email protected]", "[email protected]", "[email protected]", .....
Kempis asked 14/12, 2011 at 13:25
3
Solved
I have an app that has a number of Post models, each of which belongs_to a User model. When these posts are published, a PublishedPost model is created that belongs_to the relevant Post model.
I'm...
Rickeyricki asked 22/1, 2013 at 23:37
5
I am attempting to nest SELECT queries in Arel and/or Active Record in Rails 3 to generate the following SQL statement.
SELECT sorted.* FROM (SELECT * FROM points ORDER BY points.timestamp DESC) A...
Chessy asked 24/5, 2010 at 4:57
5
Solved
I'm trying to learn as much as I can about AREL. But I'm not sure what to look at.
I found some documentation on rubydoc, but it doesn't seem very good in terms of showing what are the "pub...
Biflagellate asked 16/4, 2011 at 17:47
2
Solved
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 ...
Animadversion asked 23/2, 2012 at 4:37
6
Solved
I'm doing my best to bend my brain around arel and the relational algebra behind it, but how to represent a SELECT DISTINCT is consistently eluding my comprehension. Can anyone explain how to arel:...
Senzer asked 28/6, 2010 at 21:28
2
Solved
Arel 3.0.2 provides two classes to specify the join type: Arel::Nodes::InnerJoin and Arel::Nodes::OuterJoin and uses InnerJoin as default.
foo = Arel::Table.new('foo')
bar = Arel::Table.new('bar')...
3
Solved
Given
class Category < ActiveRecord::Base
has_many :products, :order => 'name ASC'
end
Using the Rails 3 stack, how can I query for all categories that 'have' products?
Ciracirca asked 17/9, 2010 at 0:17
5
Solved
I have a query that needs to return results that are NOT matched in a sub query. The sub query can return an empty result, so I need to set a default value (say 0) if the sub query returns an empty...
Speculative asked 20/12, 2010 at 3:5
3
I have a model for organisations (nested set). I have a model for people. A person can have another person as deputy. An organisation is owned by a person. An organisation is only visible to the ow...
Aldebaran asked 21/12, 2010 at 15:4
0
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!)
User...
Pell asked 23/10, 2013 at 9:2
3
Solved
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 ...
Wilhoit asked 1/8, 2013 at 12:38
2
Solved
I have a custom class, but I want to be able to pass it to Arel and let it resolve its queryable part.
module Custom
class Item
attr_accessor :name
def initialize(name)
self.name = name
end...
Proofread asked 15/6, 2011 at 13:57
2
Solved
I have a model relationship where today has many tasks
I'm trying to retrieve a user's today object, include the tasks and render them all to Json. All of this was going great until I decided I wa...
Cerise asked 18/3, 2011 at 4:32
3
Solved
I am using Ruby on Rails 3.2.2 and I would like to generate the following SQL query:
SELECT `articles`.* FROM `articles` WHERE (`articles`.`user_id` = 1 OR `articles`.`status` = 'published' OR (`a...
Metamer asked 25/6, 2012 at 14:2
1
I'd like to use something like find_in_batches, but instead of grouping fully instantiated AR objects, I would like to group a certain attribute, like, let's say, the id. So, basically, a mixture o...
Pigskin asked 21/3, 2013 at 15:27
6
Solved
I have a Rails 3 project. With Rails 3 came Arel and the ability to reuse one scope to build another. I am wondering if there is a way to use scopes when defining a relationship (e.g. a "has_many")...
Apospory asked 9/3, 2010 at 20:33
© 2022 - 2024 — McMap. All rights reserved.