Skip to main content

Questions tagged [active-record]

Active Record is a pattern that combines domain logic with storage abstraction in single object.

1 vote
1 answer
100 views

Group some given users according to their department

I have wrote following solution for one answer but I want to refactor to make it more simple and readable. I am receiving params ...
Kamal Panhwar's user avatar
1 vote
1 answer
407 views

Rails: create a relationship between comment and user

I'm trying to connect the create of a comment to the current_user. I have a model comment which is a polymorphic association. <...
Steven Aguilar's user avatar
2 votes
1 answer
375 views

Dynamically combine ActiveRecord Relation results [closed]

This isn't the actual use-case I have but for simplicity, let's say I have an ActiveRecord Animal model in a Rails app. The Animals have a name (string) and ...
kaydanzie's user avatar
0 votes
1 answer
763 views

ActiveRecord Query for many to many association

I have two Models in my Rails 6 / PostgreSQL application which have a many to many relation; Car and Driver. The goal is to get ...
Severin's user avatar
  • 153
6 votes
1 answer
991 views

Update join table using list of checkboxes in Rails

I have Gig and Singer Active Record models (standard--no customization just yet) with a many-to-many relationship through a ...
thumbtackthief's user avatar
1 vote
1 answer
112 views

Rails 5.2 callbacks to trigger score recalculation for relationships

I have a model that is in a HABTM relationship with 2 other models: Activity.rb ...
rmcsharry's user avatar
  • 121
0 votes
1 answer
63 views

Updating one model field based on the associated model's field

I'm wondering if there is any way we can optimize the following code. Scenario is Library's active field should be ...
Bibek Sharma's user avatar
2 votes
0 answers
80 views

Counting how many questions in each category are tagged

I have a homepage that shows how many questions are in a certain category which is done through tagging. The functionality is working great, it tells me how many of each there are. However, newrelic'...
mazing's user avatar
  • 121
4 votes
2 answers
124 views

A method that shows maps users are a part of

A little background: My app has two models called mapgroups and usergroups. A map belongs ...
Trenton Tyler's user avatar
0 votes
2 answers
85 views

ActiveRecord query for coaches a client has bookmarked

I'm trying to figure out the best way to set up an ActiveRecord query. Models There are three relevant models involved: ...
Phillip Longman's user avatar
0 votes
2 answers
86 views

Counting number of messages for a mailbox over several periods

The idea is to return a number of messages received today, this week, this month. ...
kirqe's user avatar
  • 103
5 votes
7 answers
3k views

Display related records, if they exist, in Rails view

Is this much logic in view is justified to check for the presence of record? ...
Rajkaran Mishra's user avatar
1 vote
3 answers
4k views

Count has_many relationships

I have 3 models: Import, Product, Values. An import has_many products. A product has_many values. I want to find the product with the highest values count and the sum of all values for all those ...
Graham Slick's user avatar
3 votes
2 answers
104 views

Rails method to match users according to language fluency level

This code works fine, but I'm still learning, and feel like there is a more Railsy way to write this. Is there a good rails ActiveRecord method I should learn more about? Please let me know if you ...
gwalshington's user avatar
3 votes
2 answers
755 views

Seed a database

I'm looking for advice / best practice to avoid doing a deeply nested set of IF/THEN statements in Rails. The intention is to ...
Mirv - Matt's user avatar

15 30 50 per page
1
2 3 4 5 6