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

Android metaio AREL launch url in app and NOT external browser

This is based on the Metaio sdk, but not sure the problem is dependant of it. I have created a basic AREL based Android app, using the Creator. On detection of marker I would like to load a url in a webview. However when the marker is detected, I…
George Mincila
  • 529
  • 5
  • 17
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
2 answers

Rails ActiveRecord finding questions by tag in named scope

I want the equivalent of SO search by tag, so I need an exists query but I also still need to left join on all tags. I've tried a couple of approaches and I'm out of ideas. The Qustion - Tag relationship is through has_and_belongs_to_many both ways…
fearofawhackplanet
  • 52,166
  • 53
  • 160
  • 253
0
votes
1 answer

RoR Queue Model

I create a RoR application. But when I add new model called Queue and these appear these error: ActionView::Template::Error (undefined method `arel_table' for Queue:Class): It's Queue a reserved word for rails or ruby? What's wrong? Thanks in…
Javier Valencia
  • 697
  • 7
  • 24
0
votes
2 answers

In Rails, can I query and only get objects that have a linked object?

So I have this object, let's call it Dog, and this other object, let's call it Collar. class Dog < ActiveRecord::Base has_one :collar end class Collar < ActiveRecord::Base belongs_to :dog end Can I get a list of dogs that have collars? Ideally…
Aldric
  • 59
  • 4
0
votes
1 answer

Rails3 Arel Building the Where Clause

I'm trying to build the where clause using AREL but this does not execute the query: rec = self.where('color' => color_passed) rec = rec.where('make' => make_passed) if make_passed.present? rec = rec.where('year' => year_passed) if…
oprogfrogo
  • 2,005
  • 5
  • 31
  • 42
0
votes
1 answer

Correct sql (arel) for this query?

I have two tables, one with users, the other with profiles. Each table has a created_at column, where I want to update profiles.created_at so that it is the same as the corresponding row (determined by user_id) in users.created_at. In Rails, I might…
Damien Roche
  • 13,189
  • 18
  • 68
  • 96
0
votes
2 answers

rails: count and group with joined tables

I have the following models: Car: has_many :car_classes CarClass: belongs_to :Car belongs_to :CarMainClass CarMainClass: has_many :car_classes What I want to do is to count the amount of cars in CarClass grouped by the car_main_class_id but…
Sobremesa
  • 58
  • 3
0
votes
1 answer

How to mix/refer/call a custom ActiveRecord method in Arel

I have a model in which I have implemented a method that returns a set of records. Is it possible refer them in Arel? class A < ActiveRecord::Base #associations here def self.mymeth #return a set of records based on a query …
Bala
  • 11,068
  • 19
  • 67
  • 120
0
votes
2 answers

Rails arel table query with Date and Time

I am having problems with a query because midnight conversion is not working as expected. time = Date.today.midnight #=> Mon, 15 Jul 2013 00:00:00 BRT -03:00 time.class #=> ActiveSupport::TimeWithZone condition =…
Marcelo
  • 1,702
  • 2
  • 24
  • 42
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

How can I select desired columns without getting ActiveModel::MissingAttributeError?

I am trying to retrieve 2 columns from a mysql database to use with FullCalendar, using Ruby but I keep getting the ActiveModel::MissingAttributeError. What is the correct way of doing this? I have tried the following and checked SO but no luck.…
0
votes
1 answer

Simplify multiple calls to ActiveRecord #find down to single line/SQL statement

I'm having a little brain block when it comes to condensing the use of two #find methods in ActiveRecord down to a single statement and SQL query. I have a Sinatra route where the slug of both a parent and child record are supplied (the parent has…
Phil Ostler
  • 429
  • 3
  • 14
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

PgSQL - to_tsquery and JOINS leads to Error in Rails

I have the following query: query = param.tag_list.join("|") title = "ts_headline(title, query) AS title" rank = "ts_rank_cd(tsv, query) AS rank" Job.select( [ title, rank, :starts_at, :slug, :job_position_id, :id, :city_id, …
user287689