Data dodania Pytanie
2017-03-14 17:03 Inconsistent results when passing array to ActiveRecord#where »
I'm using Rails 4.2.7.1, Ruby 2.3.1 and MySQL as my DB. I have a background job that is responsible for collecting analytics about the database which ...
(1) odpowiedzi
2017-03-14 02:03 Count fails with aggregate function in Rails »
I have a query like the following: Author.select('authors.*, max(books.published_at) as last_publishing') .joins(:books) .group('authors.id') T...
(0) odpowiedzi
2017-03-13 17:03 ActiveRecord log which query went to which database »
In an ActiveRecord application with multiple connections to different databases, nothing in the log indicates which query went to which database. The...
(3) odpowiedzi
2017-03-13 16:03 List of ActiveRecord DB datatypes as symbols/strings »
This is a really short question: Is there a list of all datatypes I can use for columns in a mysql database with ActiveRecord? I know the datatypes a...
(1) odpowiedzi
2017-03-13 09:03 How to convert an active record with associations to a nested hash? »
SO... I am writing some code that will query an active record with associations and return the data in a format similar to... [{ foo: { ...
(3) odpowiedzi
2017-03-12 11:03 Query serialized array of Time objects and return ActiveRecord::Relation objects »
I'm storing Time objects in a serialized array, defined like this: Class Message < ApplicationRecord serialize :sent_at, Array end Is there an...
(0) odpowiedzi
2017-03-11 22:03 Getting PG:UndefinedTable: ERROR: when running migration to add friendships table (In development) »
I'm trying to build an app that has users and friendships. I am using Rails 5, Ruby 2.4.0, and PostgreSQL 9.5.6 I'm currently trying to implement th...
(1) odpowiedzi
2017-03-11 20:03 Active Record how to preload join for scoped relationships »
Thanks for taking a look at my question. I'm working on a Rails 5 API and am having trouble with a specific query. My db has 2 models - players and ...
(1) odpowiedzi
2017-03-11 18:03 Rails - how to protect an attribute against updating from outside of the model »
In Rails 5 I have a model with an attribute, value of which is never set directly but is always calculated in before_save callback instead. I would li...
(1) odpowiedzi
2017-03-10 18:03 Using scopes with to_json »
Is there any way to limit the association results returned by to_json in a call like Company.all.to_json(:only=>[:name],:include=>{:users=>.....
(0) odpowiedzi
2017-03-10 09:03 Why before_create callback overrides create! params? »
This code drives me crazy. Should not passed params inside create! method override padding value set by set_padding method? Banner.create!(padding: {...
(3) odpowiedzi
2017-03-10 04:03 How to modify a model after passing validation? »
I think I have to register an Active Record callback but I don't know which one. From what I understand, after_validation is called even when the val...
(1) odpowiedzi
2017-03-09 19:03 Query where based on the values of a field that is an array »
I have a class User that has a field permissions that is an array. t.text "permissions", default: [], array: true The array permissions could h...
(2) odpowiedzi
2017-03-09 13:03 Rails model design for has_many with filter model »
I have a Client model that has_many :orders but each order also belongs_to :order_type. The OrderType here is used as filter table basically since eac...
(2) odpowiedzi
2017-03-08 07:03 When using change_column_default on a column with no default, what should be the 'from' value? »
This is my create table migration. Please note that I didn't provide the default value for price. class CreateProducts < ActiveRecord::Migration[5...
(1) odpowiedzi
2017-03-08 07:03 Change 'ORDER BY' Chain on ActiveRecord Subset »
Background: I have Product model which includes 4 categories class Product < ActiveRecord::Base enum category: [:recent, :cheapest, :most_expen...
(1) odpowiedzi
2017-03-08 04:03 Why can't I query from an activerecord relation using joins? »
I am trying to figure out why this is producing an N + 1 query. Specifically, I want to get the count of upvotes, and thought that by using the joins ...
(1) odpowiedzi
2017-03-07 15:03 How to get the results of other tables using includes or joins in Ruby on Rails »
I want to query the results of private_classes. The scenario is: class PrivateClass < ActiveRecord::Base belongs_to :private_school has_many :...
(2) odpowiedzi
2017-03-07 10:03 Unknown column in 'having clause': »
I'm working on a project where I have many users, and a user has many posts. I'm trying to get the users that have a post count over a certain thresho...
(2) odpowiedzi
2017-03-04 02:03 Sum returns null in Rails »
I am trying to subtract two value while querying the data from the database for creating a graph. but it always return null when i try the code d...
(2) odpowiedzi
2017-03-03 01:03 Spree find product without any taxons »
How can I find all the products in spree which have no taxons added? If I run Spree::Product.first.taxons I get ActiveRecord::Associations::Collectio...
(2) odpowiedzi
2017-03-01 18:03 Rails: why time datatype start at 1/1/2000 »
I have a column that I only want to store time (hour, minute, second). for example here is one migration: add_column :products, :start_hour, :time ...
(2) odpowiedzi
2017-02-28 16:02 Why does Rails runs an additional unnecessary query? »
I have the following Rails Code, in which it technically do two queries max, but for some reason, the console shows three different queries as shown i...
(3) odpowiedzi
2017-02-28 16:02 Rails map method with link_to helper combined? »
I have a model where I want all the records for the association , separated by 'and' and being displayed as a link ... So far I have a map or a link_t...
(2) odpowiedzi
2017-02-28 00:02 Rails: select records with maximum date »
In my app users can save sales reports for given dates. What I want to do now is to query the database and select only the latest sales reports (all t...
(2) odpowiedzi
2017-02-27 18:02 Using includes with nested polymorphic association »
I am working on a Rails 5 project and have a model called Upvote that is polymorphic and belongs to either an Event or Suggestion. I am trying to spec...
(1) odpowiedzi
2017-02-27 13:02 How to use nested exposure when referencing the same model twice? »
I have a grape entity for a Contact model, which references User model twice: class Contact < ApplicationRecord belongs_to :user, foreign_key: :...
(0) odpowiedzi
2017-02-27 10:02 How to get all has_many objects in all model instances? »
I have the Event model. It has_many :participants. Can do Event.all.each do |event| and then try to manipulate event.participants But is there an ea...
(4) odpowiedzi
2017-02-26 22:02 Cast as Float returns ActiveRecord::StatementInvalid: Mysql2::Error »
So I am doing the following in Rails 4.2.7 @product.reviews.select('CAST(answer_1 AS FLOAT) AS answer_1') Unfortunately this returns ActiveRecord::...
(1) odpowiedzi
2017-02-26 13:02 Rails Connection Config shows incorrect details »
When i check on ActiveRecord::Base.connection_config it is showing wrong information in db it should have been PgRails5_[env] => {:adapter=&...
(0) odpowiedzi
2017-02-26 08:02 create calls before_save multiple times »
I have a before_save callback in my model which encrypts 2 fields before they're saved to the database. class Account < ActiveRecord::Base befor...
(1) odpowiedzi
2017-02-25 02:02 Can i cache a parent in rails? »
I have this code: Business.all.limit(50).each do |business| card = {name: business.name, logo: business.logo, category: business.category.name} f...
(1) odpowiedzi
2017-02-24 21:02 How can I define an after_add method on the relation class instead? »
I have a Character class and a Siblingship class. To denote that one character is a "sibling" of another, I save a Siblingship instance with a charac...
(2) odpowiedzi
2017-02-24 12:02 Active Record Filter on Two Models »
I am building a reservation system where users can search for an open reservation. Reservation has an :on scope that filters the reservations that are...
(3) odpowiedzi
2017-02-24 08:02 What is ClassName::create in Rails »
I ran into is this code: run Athlete::Create do |op| return redirect_to op.model, notice: 'Athlete was successfully created.' end I'm used to the...
(2) odpowiedzi