neo4jrb / neo4apis-activerecord

An ruby gem to import SQL data to neo4j using activerecord
MIT License
28 stars 15 forks source link

unable to handle tables without primary key #10

Open ck3mp3r opened 9 years ago

ck3mp3r commented 9 years ago

/Library/Ruby/Gems/2.0.0/gems/neo4apis-activerecord-0.8.0/lib/neo4apis/table_resolver.rb:29:in `block in identify_primary_key': Could not find a primary key for AccountContentset. (Neo4Apis::TableResolver::UnfoundPrimaryKeyError)

The table in question contains 2 foreign keys and is just used to form a many to many relationship.

cheerfulstoic commented 9 years ago

This is a good point. I have some discussion in this realm here: https://github.com/neo4jrb/neo4apis-activerecord/issues/8 but it should definitely be addressed more thoroughly. I've put this on my list (though you're welcome to look into it as well)

ck3mp3r commented 9 years ago

I'd love to help but my knowledge of ruby is limited to Chef recipes...

cheerfulstoic commented 9 years ago

I totally understand and no worries. If you would like to help I'll give you (and anyone else reading) a quick rundown of how the gem works below. You're also welcome to drop by our chat room on Gitter

So the quick overview:

The gem depends on neo4apis which is a gem that lets you set up a class which you can then hand objects to and which will take those objects and create Neo4j nodes and relationships from them. The main file that does that for neo4apis-activerecord is this:

https://github.com/neo4jrb/neo4apis-activerecord/blob/master/lib/neo4apis/activerecord.rb

In the end what that's doing is calling the add_node and add_relationship methods from neo4apis which do the work of generating Cypher queries and batching them up for import. That file also uses a couple of helpers (model_resolver.rb and table_resolver.rb).

Lastly there is a CLI (command-line interface) class which inherits from Neo4Apis::CLI::Base (again, from the neo4apis gem), which further inherits from Thor (see the Thor page). This is used to specify the commands and options which you can use when using neo4apis-activerecord from the command line.

So again, I wrote that because it's good to have out there. This gem might be a lot if you're not as familiar with Ruby or ActiveRecord, but you've got to start somewhere, right? ;)

Important note: Something that I just thought of. I'm not sure how you're using the gem, but if you're defining some ActiveRecord models (either in a Rails app or not) then I think you could define a has_and_belongs_to_many association and have it work for you. Check out my blog post introducing neo4apis-activerecord for details:

http://blog.brian-underwood.codes/sql/neo4j/neo4apis/activerecord/announcements/2015/01/08/loading_sql_to_neo4j_like_magic/

ck3mp3r commented 9 years ago

Hi,

that is the blog post I read before trying out the tools...

I'm currently trying to generate the CQL using SQL... let's see how that goes.