Hi,
I have an Author model and a Book model.
When the Author has many embedded Books, is it possible to query for all Books in mongoid (rails 3.0.1) or do I always have to fetch the Author to get the Books?
Best regards, sewid
Hi,
I have an Author model and a Book model.
When the Author has many embedded Books, is it possible to query for all Books in mongoid (rails 3.0.1) or do I always have to fetch the Author to get the Books?
Best regards, sewid
You can query embedded documents, just qualify the name. Now, this will return all Authors that have books that match your query.
If Author is defined as having many :books (and book is an embedded::document)
@authors_with_sewid = Author.where("book.name" => "sewid").all
You'd then need to iterate over the authors and extract the books.