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!!!
It should work:
Of course include your current values to the
unread_status,adminandadmin_idpart.