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

DB Result: Bind custom behaviour #56

Closed
joeholdcroft opened this issue Jun 10, 2013 · 1 comment
Closed

DB Result: Bind custom behaviour #56

joeholdcroft opened this issue Jun 10, 2013 · 1 comment

Comments

@joeholdcroft
Copy link
Contributor

Often we have custom assignment behaviour to do on top of bind(), for example setting the authorship data requires some custom code. It'd be nice to be able to pass in an anonymous function to deal with this assignment for each row. For example:

$result->bind('MyObject', function($row, $object) {
    $object->authorship = new Authorship;

    $object->create(new DateTimeImmutable('@' . $row->created_at), $row->created_by);

    if ($row->updated_at) {
        $object->update(new DateTimeImmutable('@' . $row->updated_at), $row->updated_by);       
    }
});


$result->bind(function($row) {
    $object = new Object('something');
    $object->authorship = new Authorship;

    $object->create(new DateTimeImmutable('@' . $row->created_at), $row->created_by);

    if ($row->updated_at) {
        $object->update(new DateTimeImmutable('@' . $row->updated_at), $row->updated_by);       
    }

    return $object
});
@lsjroberts
Copy link
Contributor

Added a bindWith method 6c60b63 which solves the second method above.

Also see mothership-ec/cog-mothership-commerce@aea5a81

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

No branches or pull requests

3 participants