Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7920541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:15:27+00:00 2026-06-03T16:15:27+00:00

hi I have two rails model class Feedback < ActiveRecord::Base has_many :conversations, :dependent =>

  • 0

hi I have two rails model

class Feedback < ActiveRecord::Base
  has_many :conversations, :dependent => :destroy

class Conversation < ActiveRecord::Base
  belongs_to :feedback, :touch => true

in the schema

create_table "conversations", :force => true do |t|
t.text     "content"
t.integer  "feedback_id"
t.datetime "created_at"
t.datetime "updated_at"
t.string   "author"
end

create_table "feedbacks", :force => true do |t|
t.datetime "created_at"
t.datetime "updated_at"
t.string   "status"
end

note that i have taken out columns and relationships from the models that do not matter for this question so please kindly don’t suggest I restructure the models differently

In my controller i have a method where I want to select feedbacks with status “unread” and whose last updated conversation’s author is “admin”

i know that the following selects feedbacks with status “unread”, but how do i expand on it to select those which meets my conversation author requirement?

@feedbacks = Feedback.where(:status => "unread")

I found this website (http://m.onkey.org/find-users-with-at-least-n-items) which seems to be doing something remotely similar in that it selects parent based on conditions related to child model, but still trying to figure out how to modify it for my case…

thanks much in advance!!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T16:15:30+00:00Added an answer on June 3, 2026 at 4:15 pm

    It should work:

    @feedbacks = Feedback.includes(:conversations).where("status = ? and conversations.author = ?", unread_state, admin_id).select{|a| a.conversations.last().author == admin}
    

    Of course include your current values to the unread_status, admin and admin_id part.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a rails model class class Model < ActiveRecord::Base has_many :object_collection def add_object(object)
I have the model Post: class Post < ActiveRecord::Base has_one :location, :dependent => :destroy
I have a ActiveRecord Car model: class Car < ActiveRecord::Base def check_value puts self.load_size
so I have two models: class User < ActiveRecord::Base has_and_belongs_to_many :followed_courses, :class_name => Course
I have an Item model class Item < ActiveRecord:Base has_and_belongs_to_many :orders end And an
I have two models with a one-to-one association. class User < ActiveRecord::Base has_one :setting
I have two models/tables in my Rails application: discussions and comments. Each discussion has_many
I working in Rails 3 Activerecord. I have two models City and Shipment and
In my rails 3 model, I have two classes: Product, Service. I want both
I have a Rails model which I use two has_one relations: requester and friend

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.