Vinelab / NeoEloquent

The Neo4j OGM for Laravel
MIT License
636 stars 200 forks source link

Best Practices for Relationship with MySQL table/columns #305

Closed NicksonYap closed 4 years ago

NicksonYap commented 6 years ago

Hi,

We've just tried this package Relationships with NeoEloquent Models work

However, when we try relationship with Laravel's original Eloquent, it throws an error saying the class must be NeoEloquent, not Model

Are there any best practices to relate with MySQL?

Thanks

heydavid713 commented 6 years ago

Here is the real problem: you are trying to establish relationship of Apples with Oranges. You would have to either have to connect both databases directly (no easy feat) or create the "relationships" using Laravel as the common path. NeoEloquent (or Eloquent for that matter) cannot do this automatically for you since they translate the Builder queries to their respective language and well you just can't have half a query in Cypher and the other half in SQL can you?

Hope that made some sense for you. I can try and explain a bit better if you need me to as I attempted to do this a few years ago.

NicksonYap commented 5 years ago

The simple idea I have is to use custom attributes or custom functions in the Model.

For example:

User has many Photos

User is from MySQL/Eloquent and Photos are from Neo4j

The Photos in Neo4J can carry the MySQL row id of the User Or 'Photos' can point to a virtual User node in Neo4j, which defines the MySQL row ID

So when calling:

User::find(1)->photos();

It will return NeoEloquent Class with the relevant Photos (based on the user id in Neo4j)

What do u think? @heydavid713

yassir3wad commented 5 years ago

@NicksonYap https://github.com/Vinelab/NeoEloquent/pull/321

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.