Data dodania Pytanie
2017-04-11 22:04 QUERY: where has_many association does not contain specific value »
I have two models Invoice and InvoiceEvent Invoice has many InvoiceEvents InvoiceEvent has a field state I'd like to write a query to find all Invo...
(1) odpowiedzi
2017-04-11 10:04 Rails STI associations and nested attributes »
I have a structure like the following: class Order < ApplicationRecord end class BulkOrder < Order has_many :vehicles, inverse_of: :order ...
(1) odpowiedzi
2017-04-09 04:04 composite primary key not updating after save »
Here is a minimal test case that forms the basis of my question. Why is it that even though user is properly saved, the attribute user.id isn't update...
(1) odpowiedzi
2017-04-07 10:04 Rails association query based on condition »
class ConferenceSession < ActiveRecord::Base has_many :conference_sessions end class ConferenceSession < ActiveRecord::Base belongs_to ...
(2) odpowiedzi
2017-04-06 16:04 How i group the result according to 2.degree association in activerecord »
I am trying to group blog_post that is related to category. category is related to category_group. So there is no organic bond between blog_post and c...
(0) odpowiedzi
2017-04-04 19:04 SQL in AR searching if an element is not within a column array »
date = Date.today Subscription.joins(:cart).where("'#{date.beginning_of_week(:sunday).to_s}' != ANY (carts.skipped_weeks)") The column skipped_week...
(2) odpowiedzi
2017-04-03 23:04 Rails 5 Race Condition with auto_increment column and background worker »
In a Rails 5 app I have a rake task collecting all users which have to be billed today, invoking an activejob which calls a service object to actually...
(0) odpowiedzi
2017-03-31 22:03 Rails Custom Validation Across multiple attributes »
I have a rails app with the following user models: Truck User A truck belongs to a user with the following association: class Unit < ActiveRecor...
(1) odpowiedzi
2017-03-31 21:03 activerecord model with 2 parent levels »
A user can have many questions. Many users can participate on a question and provide multiple answers to the same question. Relation between users and...
(1) odpowiedzi
2017-03-30 17:03 Sanitize raw SQL with ActiveRecord »
I'm trying to get the following request sanitized to send to a MySQL server: INSERT INTO `table` SELECT NULL, t.`id`, ?, ? FROM `table` AS t ...
(0) odpowiedzi
2017-03-28 17:03 Select sum and dynamic where statement query in Rails 4 »
I have this below statement in my controller and I want to know how to rewrite it in Rails 4 Entry.find(:all, :conditions => [@conditions.keys.joi...
(2) odpowiedzi
2017-03-27 20:03 has_many :through is only working in one direction »
I have the following has_many :through situation: class User < ApplicationRecord has_many :term_enrollments, foreign_key: 'builder_id' has_man...
(1) odpowiedzi
2017-03-25 22:03 Rails Database Query ROR »
First of all, I am still new to ROR and I am trying to come up with more efficient way to do a database query for my datatables. My Model association...
(1) odpowiedzi
2017-03-23 23:03 Is there a way in rails to make a model optionally belong to another model? »
I am building a rails exercise app that has both exercises and routines. I want each routine to be composed of several exercises (has_many :exercises)...
(2) odpowiedzi
2017-03-22 16:03 rocketpants cache expose data »
In Rocketpants, you expose data to clients through expose method. Like expose competition, methods: [ :goals ] Since expose met...
(0) odpowiedzi
2017-03-22 15:03 Can you use the JDBC adapter on MRI ruby »
We're dealing with OCI issues with MRI Ruby and would like to use the gem activerecord-jdbc-adapter to simplify the process. Is it possible to use JD...
(1) odpowiedzi
2017-03-22 14:03 Rails 5 pluck alias_attribute not work on Activerecord_Relation »
I have got Rails 5 application which use mariadb. This database is configured to read table from another MSSQL database using MariaDB Connect Engine. ...
(0) odpowiedzi
2017-03-21 17:03 Alternative to using 'order' within an array »
I've been doing some edits to an output when working with some records and i've ran into a problem where the sorting option no longer is working. In...
(3) odpowiedzi
2017-03-21 10:03 Edit rails form dynamically through select tag »
I have a providers Table generated with Scaffold & have filled in the names (text_fields) of all the providers. now im trying to edit them dynamic...
(0) odpowiedzi
2017-03-20 23:03 How do I specify this `WHERE` condition without using SQL? »
I'm using the following raw Postgres SQL in my where() call to find records where some_date is two days from now: SomeModel.where('date(some_date) - ...
(1) odpowiedzi
2017-03-18 23:03 How do I update a postgres boolean field using Active Record in Rails 5? »
I created a join table like so: class CreateJoinTablePurchaseUser < ActiveRecord::Migration[5.0] def change create_join_table :purchases, :u...
(1) odpowiedzi
2017-03-16 21:03 .last method working weirdly rails »
I have an Model named Page class Page < ApplicationRecord has_many :details, dependent: :destroy end and Detail class Detail < Application...
(0) odpowiedzi
2017-03-15 22:03 Rails Query Active Record By Pairs OR'ed »
I have an API that looks like... get(not_unique_id:, pairs: []) ...where pairs can look like [{ foo: 1, bar: 'a' }, { foo: 2, bar: 'b' }] and I wan...
(1) odpowiedzi
2017-03-15 19:03 Rails: Include Model based on column value »
Consider the pseudo models: Product id type - enumerable 'book' or 'magazine' Book ...attributes Magazine ...attributes Whe...
(2) odpowiedzi
2017-03-15 18:03 How can I simulate `OR` conditions for `has_many` association in Rails 5? »
I want to simulate OR conditions for has_many association so I do not lose active record association. I understand this can be achieved using scope or...
(1) odpowiedzi
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