Data dodania Pytanie
2017-08-21 21:08 In Rails, ActiveRecord-based query returns a different set for Postgres and other database types »
This is using Ruby 2.3.3 with Rails and ActiveRecord 5.1. Taking this query as an example. Quizz .select('questions.id as qID, questions.tex...
(0) odpowiedzi
2017-08-21 08:08 Avoid Activerecord relation to be reloaded in Rails »
Lats say I have some relation: @active_posts = Post.where(active: true).limit(3) # returns 3 active posts, but there are much more then 3 Then I m...
(1) odpowiedzi
2017-08-20 22:08 Rails: Query for has many through associations »
I have following associations class Post < ActiveRecord::Base has_many :categorizations has_many :categories, through: :categorizations class...
(1) odpowiedzi
2017-08-17 16:08 Yii2: How to convert query with subquery to Actived Record? »
I want to convert this very simple SQL query with a subquery to Yii Active Record (I am using PostgreSQL). SELECT totals.name, FROM ( SELECT ...
(1) odpowiedzi
2017-08-16 10:08 Ruby on Rails: has_many self join »
Rails 5. I have been trying to create a self referencing has_many relationship based on this tutorial: https://medium.com/@jbmilgrom/active-record-m...
(1) odpowiedzi
2017-08-16 03:08 Reverse query on a has_many :through »
Scenario: Team has_many :players, dependent: :destroy has_many :users, through: :players Player belongs_to :team belongs_to :user User So, let'...
(3) odpowiedzi
2017-08-15 23:08 Rails find all records for a collection of records »
class Post < ActiveRecord::Base has_many :categorizations has_many :categories, through: :categorizations class Categorization < ActiveReco...
(3) odpowiedzi
2017-08-14 16:08 Affected rows for ActiveRecord::Base.connection.execute with Postgres »
Is there a way to get the number of affected rows resulting from a SQL operation using ActiveRecord::Base.connection.execute? I found this answer fo...
(1) odpowiedzi
2017-08-14 14:08 Relational ActiveRecord ruby on rails »
I just post because I can no longer think, I am running in circles since this morning, I am really not far from succeeding the config of my database b...
(2) odpowiedzi
2017-08-13 12:08 rails sort_by method in descending and offset limit »
i just wondering do offset limit and ordering by descending in my custom method rails after i called sort_by total_like method. this is my custom met...
(1) odpowiedzi
2017-08-12 01:08 change has_many to has_one relation »
I'm trying to convert models from has_many relation to has_one here is my code models class Activity < ActiveRecord::Base has_many :product_ou...
(1) odpowiedzi
2017-08-12 01:08 Referencing parent activerecord after using :through »
this is the structure defined in my model. class Event < ActiveRecord::Base has_many :messages has_many :conversations, through: :messages...
(0) odpowiedzi
2017-08-10 19:08 how to order of has_many through by a specific field »
I have 3 models: member, team, and team_enrollment. The structure is as follows: class Member < ApplicationRecord has_many :team_enrollments ...
(1) odpowiedzi
2017-08-10 19:08 Rails 5 - Using scope method with associated models query »
I am trying to create a scope method that queries only records that have been recently updated (or their associated models have been recently updated)...
(1) odpowiedzi
2017-08-10 03:08 How to properly scope and optimize this model queries in Rails 5 with AR »
I have an API with Rails 5.0.5 in API mode. On every controller request we respond with render json: using Active Model Serializers. We use postgresq...
(1) odpowiedzi
2017-08-09 17:08 How to convert a plain sql query with subqueries to use rails active record »
I have tried converting this plain sql query to rails active record but I am unable to do so. select vote_shares.election_year as vs_election_nam...
(2) odpowiedzi
2017-08-07 16:08 Get all records that exist in both the tables »
Below are two tables with some sample data :- Uploads: id: 1 , file_ref:abc id: 2, file_ref: abc1 id: 4, file_ref: abc3 id: 5, file_ref: abc4...
(3) odpowiedzi
2017-08-07 15:08 How to get latest comments from each post in Rails? »
I have a standard blog models, user, posts and comments. How can I query for 1 latest comment of each post of custom user? I know we can connect user...
(2) odpowiedzi
2017-08-06 18:08 Rails: How to make recent blog posts appear first »
I'm creating a blog app with ruby on rails. I was able to allow a user to add posts, but on the top of the page, the posts that were created first app...
(3) odpowiedzi
2017-08-03 20:08 Error handling of csv upload in rails »
I have this import method in my active record which I use to import the csv file. I want to know how to do the error handling of this in the active re...
(1) odpowiedzi
2017-08-03 15:08 Activerecord store only returns empty hash after rails 5 upgrade »
I am in the process of upgrading a rails 4.2 application to rails 5. One of the models uses an ActiveRecord::Store. When retrieving records after the ...
(0) odpowiedzi
2017-08-03 02:08 Ruby NoMethodError: undefined method `messages' for []:Array »
Since google did not help me in my quest to figure this out, I figured I would share it for anyone else that runs into this problem: When attempting ...
(1) odpowiedzi
2017-08-02 17:08 Mimic Active Record Relation Render Behavior »
I would like to mimic the rendering behavior of ActiveRecord::Relation in my own class. Specifically, when you instantiate an ActiveRecord::Relation, ...
(1) odpowiedzi
2017-08-01 17:08 Rails skip certain columns on Save/Update with different locales »
While saving/updating in rails, is it possible to skip/disregard a column if conditions are met in before_save callback ? Like for example I have a P...
(1) odpowiedzi
2017-07-31 22:07 Save multiple foreign keys in one model attribute »
I am new to Rails. Currently I am developing Rails 5 API. There are two models. BLOCK block_name -------------------------------- EMPLOYEE name emai...
(1) odpowiedzi
2017-07-31 16:07 Find all students not enrolled in specific course »
I am trying to solve this one but no success till now. I have 3 models. Course Model: class Course < ActiveRecord::Base has_many :student_co...
(2) odpowiedzi
2017-07-31 08:07 Difference between Model.offset().limit() and Model.limit().offset() »
I don't understand the reason for doing Model.limit(6).offset(5) when we have to get 6 elements starting from the 6th index. I think that it should be...
(3) odpowiedzi
2017-07-28 21:07 How do I store an entire object in a through table with Rails and ActiveRecord? »
I need to be able to store an entire object's values in a Rails serialized ID hash in a "through" table. What is the proper way of setting up the mode...
(0) odpowiedzi
2017-07-28 14:07 Silent failure in creating child record even with create! in Rails - expected behaviour or bug? »
I ran into a weird issue recently where my previously working code for User creation stopped working without any change in the model or controller. I ...
(0) odpowiedzi
2017-07-27 19:07 calling scope with parameter with .from method »
Is it possible to call a scope with parameter in ActiveRecord query using instance methods like from (e.g. with a symbol of a scope)? How would I do t...
(0) odpowiedzi
2017-07-27 18:07 What should I name my fixture file for a model with the name Mls »
I have an activerecord model Mls in the directory app/models/mls.rb. I have the corresponding fixture in test/fixtures/mls.rb. When I run rails tes...
(0) odpowiedzi
2017-07-27 11:07 Which one is faster between map, collect, select and pluck? »
I have been using different methods to get specific field from active record. But which one is faster and preferred and how are they different? User....
(2) odpowiedzi
2017-07-26 03:07 How to get the exact matched record in rails 3? »
Items in the database: => [#<Item id: 1, item_collection: [:LAPTOP, :COMPUTER, :MOUSE, :SPEAKER]>, #<Item id: 2, item_collection: ...
(1) odpowiedzi
2017-07-25 21:07 Namespaced key lookup on Rails 5 association with ActiveRecord »
I have the following models: class Supervision::ApplicationRecord < ActiveRecord::Base self.abstract_class = true def self.table_name_prefi...
(1) odpowiedzi
2017-07-25 10:07 Is the object that comes back as a result of a database query, an array or hash? »
Was wondering what kind of form an object comes back when a query is returned from the database. For example: @Users = User.all I'm thinking that ...
(1) odpowiedzi