activerecord Questions
2
Solved
I am using active records to access the database. However, an additional feature requires me to use standard SQL query. Is it possible to use both active records and standard SQL query in the same ...
Least asked 4/6, 2011 at 23:0
3
Solved
I'm trying to get this query to work in CodeIgniter but it's spitting out an error:
A Database Error Occurred Error
Number: 1096
No tables used
SELECT *
If I put the query directly into...
Froh asked 29/1, 2011 at 19:47
4
Solved
I've written a simple query for searching a keyword in the database.
$keyword = "keyword sample";
$keyword = str_replace(" ", "%", $keyword);
$this->db->selec...
Afrit asked 20/3, 2014 at 20:21
2
Solved
I have a fat multi-tenant Rails app on Apache + mod_passenger that outputs product prices from a PostgreSQL table as follows:
Table "public.products"
Column | Type
id | bigint
name | character var...
Nursemaid asked 27/9, 2018 at 13:18
11
I'm trying to use rails 4.2.6 to develop an app. I'm trying to use postgres for database. Server starts fine but when I try loading a page it throws this "No connection pool for ActiveRecord::Base"...
Nowt asked 4/7, 2016 at 2:50
3
Solved
I'm using Rails polymorphic associations, that way some models have many cash_histories children, like this:
has_many :cash_histories, as: :cashable
But when I try to delete all cash histories f...
Epitomize asked 27/5, 2014 at 1:35
2
Solved
I was wondering if anyone knew how to do an "IN" clause in activerecord. Unfortunately, the "IN" clause is pretty much un-googleable so I have to post here. Basically I want to answer a question li...
Udall asked 16/4, 2012 at 21:18
3
Solved
I am having an issue when trying to destroy an active record instance.
It involves the following AR
class Client < ActiveRecord::Base
has_many :phone_numbers, :dependent => :destroy
has_m...
Tauten asked 7/4, 2009 at 22:9
3
Solved
I am fairly new to Ruby on Rails, and I clearly have an active record association problem, but I can't solve it on my own.
Given the three model classes with their associations:
# application_for...
Wil asked 23/11, 2009 at 5:9
5
I have a simple query need: Find a list of users who made an order since Jan 1, 2013.
In SQL, it's a very simple query.
But I'm using Rails and Active Record.
So I wrote: User.joins(:orders).whe...
Wallet asked 5/3, 2013 at 17:43
4
Solved
As far as I know, assign_attributes (unlike update_attributes) is not supposed to save the record or for that matter, any record.
So it quite startled me when I discovered that this is not true wh...
Chelseachelsey asked 29/6, 2017 at 7:57
6
I have a query like this, I want to use this query in Codeigniter.
SELECT sum(price)
FROM (SELECT price
FROM items
ORDER BY price DESC
LIMIT 3
) AS subquery;
I have did
$this->db->select...
Languish asked 2/4, 2015 at 9:44
11
Solved
How to do UNION query with PHP CodeIgniter framework's active record query format?
Quacksalver asked 11/1, 2010 at 8:37
3
Solved
I am using Rails 4.2.3 and ruby 2.2.1
I have written a scope in roles model as follows:
app/models/role.rb
scope :default, -> { find_by(default: true) }
Now when I run
> Role.default
#...
Style asked 9/7, 2015 at 22:44
4
Solved
I see in the Active Record docs, you can query for a date using a greater than / less than comparison. However, what if you want to select where date = Date.today or must I query where date is grea...
Tattoo asked 18/1, 2013 at 17:18
2
Solved
I'm thinking about efficiency, and I'm not really sure about it one way or another.
But I have a bunch of rows with multiple columns. I just need the name field from all the rows where a certain ot...
Gand asked 8/8, 2012 at 22:34
2
I am creating association pretty much identical with the Rails Guides Patient-Appointment-Physician data model. A user has many prospects through prospect_subscription. However, when trying to acce...
Undertook asked 10/1, 2022 at 9:25
3
Solved
I am using rails 3 and postrges.
I would like order by a specific priority.
Something like:
Assignment.order(priority: ['best', 'good', 'bad'])
and this will return all activerecords first wit...
Caraway asked 12/5, 2014 at 23:35
4
Solved
I have this query:
Client.select("name as dname")
Which is working fine.
Client.select("name as dname").first.dname
=> "Google"
Now I want to get all dnames as an array but pluck method do...
Marcelinomarcell asked 3/10, 2016 at 13:13
9
I need to create a case-insensitive index on a column in rails. I did this via SQL:
execute(
"CREATE UNIQUE INDEX index_users_on_lower_email_index
ON users (lower(email))"
)
This works great...
Circularize asked 30/10, 2011 at 22:55
3
Solved
How can I make a has_many through work with multiple database connections?
I have a database named "master" that holds the location information. That is updated from a separate application. Users...
Serbocroatian asked 28/11, 2011 at 21:20
3
Solved
When running the ActiveRecord migration below on the test (not production) database, large changes in db/structure.sql appear. This is reproducible. The changes are:
A small number of the expected...
Assimilate asked 19/1 at 18:18
6
Solved
I have this search in Rails 3:
Note.where(:user_id => current_user.id, :notetype => p[:note_type], :date => p[:date]).order('date ASC, created_at ASC')
But I need the :date => p[:dat...
Guimpe asked 19/11, 2010 at 11:40
9
Solved
To get a single random record from the db, I'm currently doing:
User.all.sample
But when there are 100000+ users, it takes a few seconds to load them all, just to select one.
What's the simplest...
Ulloa asked 28/3, 2018 at 3:56
2
Solved
Given a situation like: Company has_many Users
To get the Companies that have 3 Users, this works efficiently:
Company.joins(:users).group("companies.id").having("COUNT(users.id)=3")
But what's...
Pogy asked 6/5, 2014 at 11:18
1 Next >
© 2022 - 2024 — McMap. All rights reserved.