Skip to content
Advertisement

Tag: activerecord

Rails: How to use instance method in Active Record Query

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

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

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

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

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’))

Advertisement