I am having a filter query which should return all the records where either attribute (column) “status” is not “done”, or instance method “completeness_status” does not return “done” The query is something like that: Studies.where(“studies.status != ? OR studies.completeness_status != ?”, “done”, “done”) but I am getting error that column completeness_status does not exist. Unfortunately, the column status is not
Tag: activerecord
in rails i need to get all records based on a date range, ignoring the year
i am trying to get all records within a date range in rails that fall after a given start date and before a given end date, ignoring the year. the start date will just be a month. the end of the date range is a month and date. the following example is to get users with a hire date month
Rails: Finding records where a nested association is empty
In a Rails application I’m working on, I’ve got a few different models associated like this (condensed for clarity): group.rb group_member.rb newsletter.rb newsletter/author.rb newsletter/story.rb Given the above associated models, here’s the framework I’m working within: Each Newsletter has n Authors (Group Members) and n Newsletters. Each Group Member can author multiple stories for a given newsletter. Each story is one
Rails – Relation passed to #or must be structurally compatible. Incompatible values: [:joins]
I’d like to merge two queries in my rails app. Each one is not very complex but I can’t merge them. user.rb package.rb I’m running into this error: Relation passed to #or must be structurally compatible. Incompatible values: [:joins] Answer I think what you’re looking for is a subselect: This code should really be moved into the model instead of
ActiveRecord having count query condition
I have 2 models : Conversation and Message I need to retrieve all conversations that belongs to a Brand and where there are at least one message from the brand and one message from an influencer This is my query : But i get conversations that doesn’t have messages from both… What am i doing wrong please ? Answer The
How can I introduce a has_one_belongs_to_one association in Rails model?
My Rails application has users and tasks created by users. Users can also create a task and assign another user to it. I am not quite sure how to build associations here. I know since a task is created by a user, I can have an association as below, I also want to add an association for creator in the
Get users with no postings or no active postings
I have a rails schema and I have users table and postings table. I am trying to get all users that either have no postings or no active postings. Active being a column on postings that can be true or false. Is the following correct? The thing is, if the user has any postings that are active: true, I DO
How to translate this jsonb SQL query to an Active Record query?
The following data is present in my Color ActiveRecord model: id colored_things 1 [{“thing” : “cup”, “color”: “red”}, {“thing” : “car”, &…
Creating a scope in Ruby on Rails, that returns an instance of an object only if all the associated instances fit a certain condition
I have a table called Carts with a has_many relationship to another table called Subcarts. I want to create a scope that returns all instances of the Cart table where all the associated Subcarts fits …
speed up the query which is taking 2 seconds on 1000000 on active records also on PostgreSQL Sql
I’m creating a dynamic query on the server side beside the parameter. However, my query is taking 2 seconds to fetch the records. I’m passing the query through active records let me share the query and Active record rails code SELECT (custom_attribute_values.attributable_id) FROM custom_attribute_values WHERE ((“custom_attribute_id” = ’12’ AND “value_string” = ‘Female’) OR (“custom_attribute_id” = ’12’ AND “value_string” = ‘Male’))