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: ruby-on-rails
Rails: better approach in handling dynamic column export feature
Given a dynamic export feature where users could select a column they would want to include in an export, some columns are an N+1, and some require multiple joining of tables. Ex: Tables: Columns to export in UI: Customer Name, Full Address, Pets Sample result: There are 2 ways that I could think of to achieve this in rails, first
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 5 – I need to return the first record of a group, but there are records that have no group
So as the title suggests I need to return the records from a table, where these records can belong to a group. If there are several records in a group, return only the last one, and if the record does not belong to any group, return it together. I have the following tables (automation_execution) 1 –> n (automation_execution_action) 1 <—>
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
Append additional conditions to a query
I have a query where I need to add several conditions as an OR clause, because I want to use LIKE, so I can not use IN instead. So how can I add multiple OR from an array? The SQL should look like this: where ‘a’, ‘b’, ‘c’ is from an array. Answer From the Rails API docs, the .or
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
Ruby on Rails converting Timescale SQL rate code to Ruby
I’m trying to use the Rate function from timescale to generate graph data. Right now I have a database view that does this using the concepts from the SQL code below from TimescaleDocs: Is there a way to convert this directly to ruby code in a timeseries model to improve runtime? Answer It’s possible, but I bet building the same