I just started a new project in Rails 4 and Mongoid 4 beta and an old behaviour that I used a lot in Mongoid 3 is not working anymore.
Before I used to write Model.only("field").to_a
and I would get an array with id
and field
, all other fields were set to null.
If I try to do this in Mongoid 4 I get: (Object doesn't support #inspect)
Model.only("field").map {|e| e.field}
is working although not as before. The id
is not included anymore, I get ActiveModel::MissingAttributeError
if I try to access the id.
I know I can use Model.pluck("field")
, this will not return an array of documents though.
Are these changes real or am I missing something?
EDIT:
As I'm writing this I tried including the id
and it's working. ie. Model.only("id", "field").to_a
working as before, but my question is still valid. Do I have to include the id
now in order to get an array of documents
?