Last active
March 26, 2018 05:27
-
-
Save n1215/97b8f8517e56032ceebbaf28669edeb6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$query = RelationShipQuery::new( | |
'select * from `posts` where id = :id', | |
function (array $record) { | |
return new Post($record['id'], $record['title'], $record['body'], $record['author'], $record['comments']); | |
}, | |
[ | |
'author' => PostBelongsToAuthor::hydratedBy( | |
function (array $record) { | |
return new Author($record['id'], $record['name']); | |
} | |
), | |
'comments' => PostHasManyComments::hydratedBy( | |
function (array $record) { | |
return new Comment(intval($record['id']), intval($record['post_id']), $record['title'], $record['body']); | |
}, | |
[ | |
'author' => CommentBelongsToAuthor::hydratedBy( | |
function (array $record) { | |
return new Author(intval($record['id']), $record['name']); | |
} | |
), | |
] | |
), | |
] | |
); | |
$entity = $query->exec(['id' => 1]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment