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

Dynamic relation creation #39

Closed
deluca687 opened this issue Jul 19, 2013 · 3 comments
Closed

Dynamic relation creation #39

deluca687 opened this issue Jul 19, 2013 · 3 comments

Comments

@deluca687
Copy link

How can we add properties to existing relationships dynamically? We are able to create them within Entity classes, but how can we create them on the fly?

This was from a previous answer with the same question

There is no direct way to do it through the API at this time. While there is some work in progress, it is quite far from completed.

You can register a callback on relation creation.

$em->registerEvent(HireVoice\Neo4j\EntityManager::RELATION_CREATE, function ($type, $relationName, $from, $to, $relation) {
    // $relation is the Everyman\Neo4j\Relationship
    if ($relationName === 'GOES_TO_MARKET') {
        $relation->setProperty('foobar', 'baz')->save();
    }
});

How exactly does this return a relation to modify? How do we use this?

@lphuberdeau
Copy link
Owner

It does not return a relation, it is provided as an argument in the callback.

This is related to a missing feature tracked as #38.

@deluca687
Copy link
Author

Ah I missed that, this bundle is great, we just need a method of adding properties to relationships dynamically which your example callback seems to do, an example use case would be great as I along with others are unsure how to implement it.

Thanks for the reply

@lphuberdeau
Copy link
Owner

It's quite hard to do at this time. From the callback, you would need to figure out what the property needs to be given the from and to node.

It's quite a large chunk to add to the library to do it natively and I don't quite have enough time on my hands at this time.

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