activerecord Questions

3

Solved

How does after_touch callback work in Rails? Is it called whenever an object is updated or only when a new object is created?
Alidia asked 21/7, 2015 at 11:35

2

I want a class to belong_to other classes through a polymorphic association. What is the best way to restrict the association to a specific list of classes? I am considering using a custom validati...
Immortelle asked 18/11, 2016 at 16:14

6

Solved

I have a daterange (from, to) that i want loop through an different intervals (daily, weekly, monthly, ...) How can i loop through this dateranges? Update Thanks for your answers, i came up with...

4

Solved

I'm using Rails 3.2 and I've got a database table in which I want to find all the rows that match the following criteria: a = true and b = true and ( 0< c <1 or d=1), a, b, c, d are columns...
Flugelhorn asked 9/6, 2012 at 6:8

4

Solved

I'm wanting to use UUIDs in an app I'm building and am running into a bit of a problem. Due to UUIDs (v4) not being sortable because they're randomly generated, I'm trying to override ActiveRecord:...

16

Solved

How do I use the created_at field to get only the records that were created today and no other day or time? I was thinking of a ->where('created_at', '>=', Carbon::now()) But Im not sure tha...
Notional asked 20/10, 2015 at 22:28

2

Solved

how to validate a model with one integer property say customer_id in order table which allows customer_id but if its available it should be great then 0 class Order < ActiveRecord::Base valida...
Backward asked 4/3, 2014 at 9:0

3

I have a table of restaurants that have many reservations. Now I would like to query all restaurants and in case they have reservations for 2 people it should preload these associations. In case th...
Tosch asked 8/1, 2017 at 11:59

3

I'm getting ActiveRecord::ConnectionTimeoutError in a daemon that runs independently from the rails app. I'm using Passenger with Apache and MySQL as the database. Passenger's default pool size is...
Snazzy asked 14/11, 2011 at 18:43

3

Solved

According to this question and the documentation of attr_readonly the following should be possible: class MyModel < ActiveRecord::Base attr_accessible :foo attr_readonly :bar end m = MyModel...
Otero asked 8/7, 2012 at 12:12

3

Solved

I have a large number of Product objects, that all have an associated "variant" with them. I can't just delete_all products because I need the association to be deleted as well. When I use Produc...
Straub asked 7/2, 2018 at 2:25

4

Solved

Im looking to query all Users without Comments in a single sql query? Models: class User < ActiveRecord::Base has_many :comments end class Comment < ActiveRecord::Base belongs_to :user end...
Sclerite asked 16/4, 2014 at 2:16

8

Solved

What is the difference between a belongs_to and a has_one? Reading the Ruby on Rails guide hasn't helped me.
Anneal asked 28/9, 2010 at 0:49

2

Solved

I am unable to use model.update_attribute on an attribute that is mounted by a carrierwave uploader. The SQL statement wont accept the value and adds NULL to the placeholder. If I remove the mount_...

1

My app rails app has a postgres statement timeout set to 5 seconds in production. This timeout works well for us, helps us catch errors in production, kill bad queries, etc. However, when we are de...
Flitter asked 25/2, 2020 at 19:43

4

Solved

I am writing code that will migrate some data from one database to another, over-writing some data in the destination. It uses ActiveRecord, since it's associated with a Rails app using AR already....
Bedplate asked 29/12, 2011 at 20:42

3

I have two tables: Lawyer and Phone. Phone is separated into area code and number. A lawyer has many phones. I want to produce a query that searches for lawyers who have a phone matching a phone fr...
Clarhe asked 23/4, 2012 at 23:9

5

In the logs I'm seeing a ROLLBACK, but no exception is logged. Is there a way to find out what caused the ROLLBACK? Here's the excerpt of the log: Phone Load (0.4ms) SELECT "phones".* FROM "phon...
Constrictor asked 30/1, 2012 at 6:8

5

Solved

In MySQL (and other SQL databases), it can be helpful to add comments to a table or column whose purpose may be unclear. (Search MySQL's create table syntax for "comment" for examples.) Is there a...
Centrobaric asked 8/11, 2011 at 17:19

12

Solved

I am trying to create an ActiveRecord Object.But I'm getting this error while creating it. (0.1ms) ROLLBACK ActiveRecord::StatementInvalid: PG::InFailedSqlTransaction: ERROR: current transaction i...
Effluent asked 15/1, 2014 at 13:5

6

Solved

I've been using $this->db->affected_rows() to check if updates have been successful. But this doesn't work when a user inputs the same data to be stored that is already stored (because no col...
Lea asked 17/11, 2013 at 12:27

9

Solved

When I run queries (e.g. MyModel.where(...) or record.associated_things) in the console, how can I see the actual database queries being run so I can gain more understanding of what is happening?
Boliviano asked 29/5, 2010 at 17:37

2

Solved

How to query for Companies with a certain Branch in a "has_many :through" relationship? #company.rb has_many :branch_choices has_many :branches, :through => :branch_choices "Find all compa...
Lungan asked 31/7, 2011 at 16:59

8

Solved

When I use heroku open my web app works fine but when I'm using rails s (localhost) I am running into this error: ActiveRecord::AdapterNotSpecified database configuration does not specify adapter ...
Archaeology asked 28/4, 2014 at 9:0

8

Solved

I'm writing a rake task that does some DB work outside of Rails/ActiveRecord. Is there a way to get the DB connection info (host, username, password, DB name) for the current environment as define...
Misgovern asked 30/12, 2008 at 2:37

© 2022 - 2025 — McMap. All rights reserved.