Create relationships without csv file
Steven Franchetto
Is there a way to create relationships without a relation table? For instance relationship between two tables tweet and tweet_metrics. Must I create a 'has' table that has foreign keys to both tweet and tweet_metrics or is there another way of making the relationship without making a 'has' table?
Gregory King
Hey Steven,
It depends. If one of those tables you already have contains the necessary linking information, you can use it to create the relationship.
For example, let's say you wanted to model
Tweet
s as one node and Tweet Metric
s as another node, linking the two with a HAS_METRIC
relationship. Then for example if the tweet_metrics
file was used to create the Tweet Metirc
node with its own metrics ID, but also contained the ID of the corresponding tweet in the tweets
file, then you could use that same file to map to the HAS_METRIC
relationship. This said, if there is a 1:1 relationship between the two nodes this may not be the best graph data model, you may be better mapping the same information to one Tweet node, but I won't get into that here.If you want an example similar to the one i've described here, where the same file used to define a node is used to define a relationship that connects it, check out this timestamp in the tutorial video that shows how the
order-details.csv
file of the Northwind dataset is used to define both the Order
and the relationship it has to the Shipper
node.Hope that helps!
Greg
J
Jon Schmitt
Gregory King:
Just following up on Steven's question. If I wanted to create relationships between two nodes based on already mapped properties for each node I can't do it without creating a separate relationhip csv file? For example, if you have order_id in your orders.csv file but you also have order_id in your products.csv should you able be able to create this relationship? It's almost like a left join.
Gregory King
Hi Jon Schmitt:, if I understand what you're describing correctly, it's certainly possible to map and import via the UI the example you gave, although it would be a peculiar way to organise the data. Specifically because if you had
order_id
as a column in your products.csv
file, your products would be repeated many times in the file. But you could still map and load data this way. If you mapped your products file to a Product node, specifying product_id
as the ID, it will ensure only one product is created per ID, and keep the most recent information it reads on a product in the file.Below are a couple of screen grabs illustrating such a minimal example dataset, the mappings and preview result. Hope that helps your understanding.
J
Jon Schmitt
Gregory King:
Thank you. That was very helpful. One more quick question. If I wanted to create two nodes from the same source, corresponding to two columns in csv, and connect them by an edge. How could I do this?
Is this project open source?
Thank you for the help.
Gregory King
Jon Schmitt: Hi Jon, just map the same file to each node and ensure you select the correct ID for each node property, eg a file that contains orders and products in a single file ensure you select the orderID in one and the productID in the other. If you then create the relationship between the two nodes you will find data importer will automatically map the same file used in the nodes at each end and map the relationship from/to fields for you automatically too.
J
Jon Schmitt
Gregory King:
Thank you. Using the orders and products example that you have given I want to make two nodes from the same csv file. For example, I want to have "shipCountry" --> "freight" both extracted from the same orders.csv.