Reputation: 8977
Thinking about how to model a simple graph for a Side project.
The project's users will be able to add social networks so that they can find other users with social information.
Given neo4j's architecture, which I'm new to, is the correct way to do this:
I'm leaning towards number 1 but given that I'm a newcomer I want to make sure this isn't an anti-pattern or setting me up for pain later.
Upvotes: 0
Views: 338
Reputation: 2661
Not sure if I understand you requirements correctly, but in general, it's good to model real world entities as nodes and relationships between things, quite naturally, as relationships.
In your case, I'd go one of the two following ways, depending on how much you want to do with their social media accounts.
1) A node for each social media, e.g. (LinkedIn), (Twitter), (Facebook). Then a single relationship type, call it HAS_ACCOUNT, which links (user) nodes to accounts. For example:
(user1)-[:HAS_ACCOUNT]->(LinkedIn)
2) If you find you're storing too many properties in the HAS_ACCOUNT relationship, or even that you feel like it should be linked to something else (e.g. links between social media accounts), create a node for each account the user has.
(user1)-[:HAS_ACCOUNT]->(user1LinkedInAccount)-[:IS_ACCOUNT]->(LinkedIn)
That way, your model is more flexible and you can link users account together with a different kind of relationship. Say user1 follows user2 on Twitter:
(user1TwitterAccount)-[:IS_LINKED_TO]->(user2TwitterAccount)
Hope it makes sense.
Upvotes: 2