Skip to content

Instantly share code, notes, and snippets.

@n1215
Last active March 26, 2018 05:27
Show Gist options
  • Save n1215/97b8f8517e56032ceebbaf28669edeb6 to your computer and use it in GitHub Desktop.
Save n1215/97b8f8517e56032ceebbaf28669edeb6 to your computer and use it in GitHub Desktop.
<?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