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

Rails 3.2 (ActiveRecord) association order with eager loading and ordering

I came upon this behavior in rails that I can't seem to find in the documentation. It appears that if you complicate an ActiveRecord query to the point that it lumps the underlying SQL into a "complicated" query (see below) it doesn't honor ordering…
Iamvery
  • 274
  • 2
  • 11
0
votes
1 answer

Difference between Squeel and Arel?

Can anyone explain the difference between the two very similar looking gems 'Arel' and 'Squeel' for a rails newbie. https://github.com/rails/arel Vs https://github.com/ernie/squeel I am looking forward to building a simple Query builder where user…
Nitish Upreti
  • 6,312
  • 9
  • 50
  • 92
0
votes
1 answer

Rails 3 scope, combine condition with aggregate (sum) results in error

I am having what I think is a simple problem chaining two scopes (Rails 3.2.5). I have a model called Point with fields amount and transaction_date, amongst other. Users get an amount of points for various activities, and they are "available" until…
Tom Harrison
  • 13,533
  • 3
  • 49
  • 77
0
votes
1 answer

How to get the descendants of all objects in an array? (Rails + ancestry gem)

I am using this gem https://github.com/stefankroes/ancestry for my People modle. The table looks like this: +----+----------+ | id | ancestry | +----+----------+ | 1 | NULL | | 2 | 1 | | 3 | 1 | | 4 | 1/2 | | 5 | 1/3 …
Luke Huang
  • 13
  • 4
0
votes
1 answer

Rails 3 joining 2 belongs_to associated tables

I have the following schema: class Locale < ActiveRecord::Base has_many :shops # region : String end class Shop < ActiveRecord::Base belongs_to :locale has_many :carts scope :europe, joins(:locale).where('locales.region = ?',…
KJF
  • 2,083
  • 4
  • 21
  • 38
0
votes
3 answers

Using associations like scopes

If I have the following classes class User has_many :documents end class Document belongs_to :user end I would like to be able to do the following User.where("id > 200").documents which should generate SQL like select * from…
bradgonesurfing
  • 30,949
  • 17
  • 114
  • 217
0
votes
0 answers

What does this mean? struct Arel::Attributes::Attribute not compatible (struct size differs)

I've just updated an app to rails 3.0.15, I'm not sure if that's the relevant bit, but I now get struct Arel::Attributes::Attribute not compatible (struct size differs) error right after running the server. The log shows this: tarted GET "/" for…
Victor S
  • 5,098
  • 5
  • 44
  • 62
0
votes
1 answer

Join on a subquery with grouped by in Arel?

I've searched a lot here but couldn't find a similar topic: i need to write a Query in Arel because i use will_paginate to browse through the results, so i'd loose much comfort in implementation with raw SQL. Here's what i need to spell in…
Stefan
  • 317
  • 1
  • 3
  • 11
0
votes
2 answers

Find rows with same some_attribute but two different values for user_id

These are my classes & relations class User has_many :conversation_participants has_many :conversations, :through => :conversation_participants end class ConversationParticipant belongs_to :user belongs_to :conversation end class…
Emil Ahlbäck
  • 6,085
  • 8
  • 39
  • 54
0
votes
2 answers

How to use scope in AR request with joins?

In my case I have a model Product has_one Location I use a geocoder gem to search location near a distance. The request Location.near([0, 0], 100) is look like this: SELECT locations.*, 6371.0 * 2 * ASIN(SQRT(POWER(SIN((0 - locations.latitude) *…
Ian Bernatcki
  • 108
  • 1
  • 10
-1
votes
1 answer

Nested AREL and/or query in Rails

I'm sure this will be simple for someone who knows what they are doing. I want to write this statement as a scope - and I'd rather use Arel format but can't work out the OR inside the AND select * from contacts where contact_type in (1,2) and…
user1587804
  • 121
  • 1
  • 7
-1
votes
1 answer

Using Arel for ROR I am trying to query based on my Classes associated attributes

I have a Recipe class and an Ingredient class which are connected with a has_many to a has_many through a join table RecipeIngredients. I am trying to create some filters and am trying to sort my Recipes by the number of Ingredients they contain. I…
-1
votes
1 answer

AND - OR using two alternatives in activerecord where query

I have two models where I'm performing a match between the two to work out whether they fit certain criteria. Model 1 model_type == "a" or "b" rate == Integer Model 2 a == true or false b == true or false #This defines whether or not model 2…
Carpela
  • 2,155
  • 1
  • 24
  • 55
-1
votes
4 answers

Extract records which satisfy a model function in Rails

I have following method in a model named CashTransaction. def is_refundable? self.amount > self.total_refunded_amount end def total_refunded_amount self.refunds.sum(:amount) end Now I need to extract all the records which satisfy the above…
abhinavmsra
  • 666
  • 6
  • 21
-1
votes
1 answer

Select for float value near my query number by Arel or Active Record

Suppose I have a utc_time column which stores float value I want to select utc_time values is approximate to 1402630856 And I can accept the value x,where abs (x-1402630856) < 3 So I should get the first 5 records, What should I do by Arel or Active…
newBike
  • 14,385
  • 29
  • 109
  • 192
1 2 3
48
49