Data dodania Pytanie
2017-09-13 16:09 Rails accepts_nested_attributes_for not saving association on has_many through »
I am creating a project_management application when manager creating a project at that time I also want to save developers, so for that, I created th...
(2) odpowiedzi
2017-09-13 00:09 Rails Data Modelling: How to establish relationships when 2 Objects "Share" the same has_many list? »
In a nutshell, when I create a Transaction Record it has two foreign keys. for the two users that participate in a Transaction, ie: Now, What I wo...
(3) odpowiedzi
2017-09-11 23:09 ActiveRecord::RecordNotFound in ArticlesController#show Couldn't find Article with 'id'=edit »
I am getting an error when I got into articles/edit. I am getting this error: when I should be getting this error: my code: articles_controll...
(2) odpowiedzi
2017-09-11 03:09 Validation for the count of has_many relationship in Rails »
I have been through other questions, but the scenario is little different here: class User < ApplicationRecord has_many :documents, as: :attacha...
(2) odpowiedzi
2017-09-10 14:09 Sort a resource based on the number of associated resources of other type »
I have a Movie model that has many comments, I simply want to sort them (Movies) using SQL Inside active record based on the number of associated comm...
(1) odpowiedzi
2017-09-09 10:09 ActiveRecord : which associations for places and routes? »
I would like to associates places within routes : one route has two places (start point and end point) + I need to store the distance btw those two po...
(1) odpowiedzi
2017-09-07 19:09 filter using join model ruby on rails »
I need to show posts from users who have an active subscription. model/user.rb has_one :profile, dependent: :destroy has_many :posts, dependent: :de...
(2) odpowiedzi
2017-09-07 13:09 rails attribute_changed? inside a block issue »
I have a callback which checks for the change of mobile number and creates a record in the different table if the number is changed. validate :check...
(0) odpowiedzi
2017-09-06 23:09 In Rails 5, how do I prevent find_by from returning a result if none exists? »
I"m using Rails 5. I'm confused about looking up a record by its ID. I have a model, User, but when I look up with a nil id, I get back a result ......
(3) odpowiedzi
2017-09-06 21:09 Rails 5 - ActiveRecord read and write additional attributes on join tables for self related model »
We are using a single table to store similar structure and data objects and link them together via self has_many relations. The table is called organi...
(0) odpowiedzi
2017-09-05 23:09 How to know if an associated object is merely the built one or the saved one in Rails? »
I have the following two models: class User < ApplicationRecord has_many :authentications end class Authentication < ApplicationRecord bel...
(0) odpowiedzi
2017-09-04 23:09 Size of an ActiveRecord_Relation object »
I have the following query: User.joins(:posts).group('users.id').having('count(user_id) > 1') The returned class is User::ActiveRecord_Relation....
(2) odpowiedzi
2017-09-04 18:09 Trying to refer to self inside a has_many scope in rails 5 »
I have the following setup: class TeamEnrollment < ApplicationRecord belongs_to :team has_many :term_enrollments, through: :team end The...
(1) odpowiedzi
2017-09-03 01:09 Rails Activerecord Relation: using subquery as a table for a SQL join »
Can anybody help me figure out how to write the following SQL statement in Rails? SELECT * FROM shifts a INNER JOIN ( SELECT shifts.date, shifts....
(1) odpowiedzi
2017-09-01 13:09 Arel node for an array element (suffix operator) »
Is there any arel node for suffix operators to access array elements like this: column = Table.arel_table[:column] low = here_magic_happens(column, '...
(0) odpowiedzi
2017-08-31 21:08 Activerecord::Base no connection method? »
I am porting an in house library up to Rails 5.1. We have a custom activerecord::base override that allows us to use its own database configuration. T...
(0) odpowiedzi
2017-08-31 17:08 Is there a way to chain conditionals in Ruby, Rails or ActiveRecord? »
Sometimes I find myself doing something like: def my_method item = SomeModel.where(some_attr: 'some_val').first (item) ? nil : item.method end ...
(1) odpowiedzi
2017-08-29 21:08 Mysql2::Error: Unknown column 'comments' in 'having clause' »
In a controller, I have an activequery with a sub select to get a count, and want to use the count to further limit by rows returned. e.g., comments =...
(2) odpowiedzi
2017-08-29 17:08 Ruby on Rails: Running custom validation function only when other properties are present »
I want my custom validator to only run when the properties it uses are present. # these are all dates validates :start_time, presence: true validates...
(2) odpowiedzi
2017-08-29 15:08 Ruby on rails: ActiveRecords' first_or_create is very slow »
I've got a ruby scripts which imports XML files to a MySQL database. It does it by looping through the elements in the XML file and finally table.whe...
(2) odpowiedzi
2017-08-28 21:08 ActiveRecord pluck to SQL »
I know these two statements perform the same SQL: Using select User.select(:email) # SELECT `users`.`email` FROM `users` And using pluck User.al...
(2) odpowiedzi
2017-08-28 20:08 ActiveRecord query where joined records don't exist »
Assuming models like this: Student has_many :assignments Assignment belongs_to :student Assignments have a date field "date" representing the da...
(1) odpowiedzi
2017-08-28 15:08 Get all messages between the current user and every admin »
I have model User class User < ActiveRecord::Base has_many :sent_messages, class_name: 'DirectMessage', foreign_key: :sender_user_id has_many ...
(2) odpowiedzi
2017-08-27 00:08 Rails .last clarification »
Hello I have a rails ap that runs devise... has a customer model. I have a after_create on customer that starts with @customer = Customer.last I'm ...
(1) odpowiedzi
2017-08-25 17:08 How to avoid nilClass errors »
If I try to check for values in my database, I sometimes get errors related to the fact that there were no hits from my query. So I started using .pr...
(2) odpowiedzi
2017-08-25 16:08 Rails 5. Track the order of Associations between models »
I can think of ways to implement this myself however, I'm hoping someone can link to a gem or perhaps just an applicable sorting algorithim in ruby. ...
(1) odpowiedzi
2017-08-25 03:08 Inconsistent behavior from self-referential user model »
I have the following User model: class User < ApplicationRecord has_many :friendships has_many :friends, through: :friendships end And th...
(0) odpowiedzi
2017-08-24 18:08 Many-to-many association with join table and multiple aliases »
I'm working on a geocaching application where users can create a new cache or visit an existing one. Here are the models: class User < Application...
(1) odpowiedzi
2017-08-24 16:08 Rails & ActiveRecord - Different validations for on: :create and on: :update? »
I want a User model creation/validation/update system with the following properties: Requirement 1 When a User is first created, the :name, :email, ...
(1) odpowiedzi
2017-08-24 08:08 Saving ActiveRecord's associations which are pointing to each other, at once »
I have the following models class Cargo < ApplicationRecord has_many :destinations has_many :assignments accepts_nested_attributes_for :dest...
(1) odpowiedzi
2017-08-23 14:08 Can Rails / ActiveRecord on Heroku with PG really be this slow? »
In my Rails-application I need to prevent two people from being assigned the same case. I do this by looking at an "events" table if the case has alr...
(1) odpowiedzi
2017-08-23 06:08 Include all objects but apply conditions only on associations in ActiveRecord »
With the following models, class User < ActiveRecord::Base has_many :addresses # Has an attribute named active end class Address < ActiveR...
(3) odpowiedzi
2017-08-23 03:08 Rails ActiveRecord combining result of multiple queries »
Model: player belongs_to :current_club belongs_to :parent_club has_many :ratings rating belongs_to :player Basic Schema: create...
(1) odpowiedzi
2017-08-22 21:08 return x amount of each group in rails by has_many »
I'm a rails newbie so pardon if this is a basic question.I extended domain model by has_many has_many :stream_filters has_many :active_filters, ...
(1) odpowiedzi
2017-08-22 18:08 How to perform autoclearing associated table rows without valid associated id »
I am trying to find a way to clear rows from table which is associated with another table. The point is that I am trying to create application for re...
(1) odpowiedzi