Say I have a record called Post that has many comments.
Now I run the following code:
p = Post.new
p.comments.build(:title => 'great')
I would now like to locate that comment by its title.
If the record was saved, I could do something like
p.comments.find_by_title('great')
But since it isn’t saved yet, that’s going to return nil (because it actually runs an SQL query)
Is there a way to locate this record before it’s saved?
Thanks!
1 Answer