I am not sure whether I should ask this question on SO or not. But I have to as I don’t have clear idea about my doubt. I was told not to set default values in rails migrations and use null values instead in a code review by our CTO. And his explanation is like this once the database gets
Tag: ruby-on-rails-4
How to use ANY instead of IN in a WHERE clause?
I used to have a query like in Rails: Which generates sql query like: Now I want to change this to use ANY instead of IN. I created this: Now when I use empty array ids = [] I get the folowing error: Answer There are two variants of IN expressions: expression IN (subquery) expression IN (value [, …]) Si…
Rails Activerecord Relation: using subquery as a table for a SQL select statement
Can somebody help me figure out how to write the following SQL using Rails (I’m using Rails 4) Activerecord methods? I know you can do this with find_by_sql but I’d like to preserve the active record relation. Here’s the sql for a postGreSQL db that I’m trying to create: For my subquer…
Rails select() and count() don’t seem to play nice
I’ve noticed something odd with Rails (4.1) ActiveRecord, where select and count sometimes mix badly: User.all.count => 103 User.all.size => 103 User.all.length => 103 So far, so good. I …
Rails User.joins.not(…) in Active Record?
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 ...