ruby on rails - 'Where' query with condition for last association record -


i want this:

post.all.select{|p| p.comments.last.type == 'specialcomment'} 

i.e. need select posts 'where' last comment has special type. how can active record query syntax?

try this:

post.joins(:comments).where("comments.last.type = ?", 'specialcomment'") 

Comments