Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return everything as object and not array #65

Closed
jgrossi opened this issue Nov 12, 2013 · 2 comments
Closed

Return everything as object and not array #65

jgrossi opened this issue Nov 12, 2013 · 2 comments

Comments

@jgrossi
Copy link

jgrossi commented Nov 12, 2013

Hi!

First thank you for the amazing work!

When getting a post, for example, I get the entire object, like:

$post = Post::find('52827b589a1ef3c65c0041a7');
echo $post->title;

But when I have comments "inside" posts - not using hasMany - I got the comments as array and not object:

$comments = $post->comments;
foreach ($comments as $comment) {
    echo $comment['author']; // will be better $comment->author
}

Does the library have some "config" to ensure returning "object" as default?

Thank you so much!

@jenssegers
Copy link
Contributor

The native MongoDB PHP driver always returns data as an array. It does not have something like PDO::FETCH_OBJ, so there is not much I can do about it.

@jgrossi
Copy link
Author

jgrossi commented Nov 12, 2013

Sure! Actually I'm doing something like:

$comment = (object) $comment;
echo $comment->author;

So maybe an option to retrieve them like FETCH_OBJ will be a good idea.

No problem! Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants