mongodb / laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel (Moloquent)
https://www.mongodb.com/compatibility/mongodb-laravel-integration
MIT License
7k stars 1.43k forks source link

Problem nesting Eloqent methods #123

Closed davemathews closed 10 years ago

davemathews commented 10 years ago

I tried using the Moloquent as below which works within eloquent to return things as expected. //Should return the given value in the column name for the given find id Model::find($id)->first()->column_name;

This works in Eloquent just as expected but in the Moloquent example it instead ignores the find($id) and just returns the first record in the database instead of the one I was looking for. //Had to change to this Model::find($id)->get()->toArray()['column_name'];

This is just an FYI that in this case nesting the methods does not return as expected from Eloquent.

jenssegers commented 10 years ago

find returns a single object, why are you calling first on it?

davemathews commented 10 years ago

I can understand that, my point was while that was not an expected use, it did not give an expected result, was not sure if it was going to lead to other issues possibly.

jenssegers commented 10 years ago

It should return the same result as Eloquent. You're calling find which returns a model instance, and then you call first which (is passed to the query builder) returns a different model instance. So it should actually ignore the first find.