active-relation Questions
17
Solved
I've written a couple of complex queries (at least to me) with Ruby on Rail's query interface:
watched_news_posts = Post.joins(:news => :watched).where(:watched => {:user_id => id})
watch...
Grubb asked 13/7, 2011 at 23:34
5
Solved
Example
class User
has_many :tickets
end
I want to create association which contains logic of count tickets of user and use it in includes (user has_one ticket_count)
Users.includes(:tickets...
Bombazine asked 9/2, 2012 at 10:29
4
Solved
I would like to perform an ActiveRecord query that returns all records except those records that have certain ids. The ids I would like excluded are stored in an array. So:
ids_to_exclude = [1,2,3...
Stinson asked 3/1, 2011 at 0:49
3
Solved
If I have an association name as a string, is there a way I can get a handle on the association object?
For example:
o = Order.first
o.customer will give me the customer object that this order ...
Pedicab asked 2/7, 2013 at 18:4
4
Solved
Suppose I have the following models:
class Post < ActiveRecord::Base
has_many :authors
class Author < ActiveRecord::Base
belongs_to :post
And suppose the Author model has an attribute, ...
Farinaceous asked 9/2, 2012 at 3:33
1
First, I am getting the review statuses between particular dates.
date_range = Date.parse(@from_date).beginning_of_day..Date.parse(@to_date).end_of_day
@review_statuses = ReviewStatus.where(updat...
Marriageable asked 23/5, 2018 at 13:43
3
Solved
I have searched but not able to find the brief explanation for the difference between ActiveRecord and ActiveRecord::relation object.
I have understand that ActiveRecord is the single object find ...
Cowry asked 12/7, 2016 at 9:55
4
Solved
I need to be able to chain an arbitrary number of sub-selects with UNION using ActiveRelation.
I'm a little confused by the ARel implementation of this, since it seems to assume UNION is a binary ...
Gymnastic asked 8/11, 2011 at 4:7
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
7
Solved
To get all posts with publisher_id equals to 10, 16, or 17, I do:
Post.where(:publisher_id => [10, 16, 17])
How would I get all posts with publisher_id not equals to 10, 16, or 17 (i.e. all p...
Untwist asked 20/5, 2011 at 4:0
4
Solved
This is related to a question a year and change ago.
I put up an example of the question that should work out of the box, provided you have sqlite3 available: https://github.com/cairo140/rails-eag...
Spongin asked 5/2, 2011 at 18:51
1
Solved
How can I turn the following SQL query into an ActiveRecord relation so that I can expand on it with scopes?
WITH joined_table AS (
SELECT workout_sets.weight AS weight,
workouts.user_id AS use...
Inflammatory asked 1/5, 2013 at 18:42
2
Solved
I have code like this:
t = "%#{term}%"
where('name like ? or email like ? or postcode like ?', t, t, t)
As you can see it's performing a search across several fields.
Is there a way to avoid th...
Crystallization asked 25/1, 2013 at 16:45
2
I'm trying to create an app in Rails 3.1 with mysql2 v 0.2.6. When running rake db:create, I get the following error:
DEPRECATION WARNING: Arel::Visitors::VISITORS is deprecated and will be remove...
Versicle asked 23/9, 2011 at 1:54
1
Solved
I have a Transaction class. Each object of this class includes one issuing account, one sending account and one receiving account. Each of these is an instance of Account class. In my Transaction t...
Sibley asked 14/9, 2011 at 2:29
3
Solved
I've looked over the Arel sources, and some of the activerecord sources for Rails 3.0, but I can't seem to glean a good answer for myself as to whether Arel will be changing our ability to use incl...
Maseru asked 20/5, 2010 at 1:33
2
Solved
I am having this unexplained ActiveRecord::Relation, undefined method error . I don't know why, since my model association are well defined and the event table has the foreign keys for the user tab...
Shorts asked 27/12, 2010 at 22:40
1
© 2022 - 2024 — McMap. All rights reserved.