-
Notifications
You must be signed in to change notification settings - Fork 15
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
Defined active record model's HABTM associations #8
Comments
It's true! I would definitely like to add HABTM associations. If people do a table import then it will actually import these associations as nodes, but if they're importing from an existing ActiveRecord app then it won't. I'm wondering if there should be an option to import tables with two foreign keys as relationships rather than nodes with two relationships and to put the key/values from that table into the relationship. Maybe when importing models it should always do this for |
I agree @cheerfulstoic and thanks for the prompt reply. I think when importing AR models, it should, like you've mentioned, keep the defined association for This will ensure that the referential integrity of the related models, when translated into neo4j land as For straight table import, with no definitive relationship, will neo4j, allow you to define relationships to link the nodes, once tables are imported as nodes? |
So neo4j's modeling is pretty simple. There are nodes and relationships. Both can have key/value pairs to store data. Nodes can have 0 or more "labels" (like So in neo4j, you can have 1:M and M:M, but they're modeled the same way: as relationships between nodes. If nodes of a particular label always happen to have many nodes leading to one node, then that could be considered 1:M, but there's nothing stopping it from being M:M. You might even say that all relationships in neo4j are M:M because relationships are a separate data store from nodes and they can always link any node to any other node. So if you use the So, with that background, to make sure that I'm being clear in my proposal: With both If a user of Either way, though, I can imagine that a table with two foreign keys could naturally be modeled as a relationship because there is a connection between the two (although direction isn't usually clear). Even if it's So the point of that was mainly to explain how neo4j works and how neo4apis-activerecord works, but it's also kind of helped my talk (or at least type) things out. I think that there should be a command-line option to import tables with just a primary key and two foreign keys as relationships, but otherwise it just imports tables as nodes and creates relationships for any foreign key references. When importing ActiveRecord, I think that all HABTM and HMT associations should be relationships. What do you think? I'd also like @subvertallchris 's opinion as well ;) |
@cheerfulstoic thanks for explaining some of the I think having another option for |
Just ran into this on the neo4j developer resources pages: http://neo4j.com/developer/graph-db-vs-rdbms/#_data_model_transformation Putting here for reference as I think it's very appropriate to the gem |
FYI I just implemented HABTM in version 0.7.0! It works if you already have it defined in your models. Haven't yet played around with building in assumptions based on table structure when there are no models |
It looks like the
Neo4Apis::ActiveRecord:: model_importer
method is able to handlehas_one
,has_many
andbelongs_to
reflected associations, which in most cases will be able to handle most of the 1:M, M:1 or M:M (with intervening model that links the many to many related tables, ex:projects
,researchers
,advisors
: a project has many advisors through researchers) relationships.However for a direct M:M relationship, with no intervening model (
departments
,employees
departments_employees
for example), which model wise, can be defined with thehas_and_belongs_to_many
association within theEmployee
andDepartment
models, will the relationship, translated into neo4j appropriately, even though it is not a handled association?The text was updated successfully, but these errors were encountered: