anlek / mongify

Mongify allows you to map your data from a sql database and into a mongodb document database.
http://github.com/anlek/mongify
MIT License
317 stars 82 forks source link

Reference structure doesn't apply #142

Closed jcheng418 closed 7 years ago

jcheng418 commented 7 years ago

Hi I tried to reference "project" and "owner" object ID into LU_object document. The translation.rb file is as following. The mongify process doesn't have any error reported.

table "lu_project" do column "id",:key column "project_id", :integer column "project_guid", :string column "project_name", :string column "project_desc", :string column "creation_timestamp", :datetime column "modification_timestamp", :datetime column "project_status", :string column "metadata_id", :integer end

table "lu_owner" do column "id", :key column "owner_id", :integer column "owner_guid", :string column "owner_name", :string column "owner_login", :string column "creation_timestamp", :datetime column "modification_timestamp", :datetime column "owner_status", :string end

table "lu_object" do column "object_id", :integer column "object_guid", :string column "object_name", :string column "object_desc", :string column "object_location", :string column "creation_date", :date column "modification_date", :date column "creation_timestamp", :datetime column "modification_timestamp", :datetime column "project_id", :integer, :references => :lu_project column "owner_id", :integer, :references => :lu_owner end

image

but the lu_object collection I get still contains project_id and owner_id with integer instead of the project object id and owner object id. Any ideas? The mongify version I'm using is 1.3.1.

anlek commented 7 years ago

Hey, thanks for the clear issue report. The reason it doesn't update the IDs is that you need to specify what the ID references to: column "owner_id", :integer, :references => :users. However, I'm not sure what your IDs are referring to, table wise. If you meant that owner_id should be the table's primary key, you just specify: column "owner_id", :key (instead of :integer)

You can read more on this via the docs: http://www.rubydoc.info/gems/mongify/

Hope that helps, Andrew

jcheng418 commented 7 years ago

Hi,

In my lu_object configuration, I specified what the Project_ID,Owner_ID references to:

able "lu_object" do column "object_id", :integer column "object_guid", :string column "object_name", :string column "object_desc", :string column "object_location", :string column "creation_date", :date column "modification_date", :date column "creation_timestamp", :datetime column "modification_timestamp", :datetime column "project_id", :integer, :references => :lu_project column "owner_id", :integer, :references => :lu_owner end

Basically, I'm hoping the Mongo ObjectID of l_uproject and _luowner tables can be referred in _luobject table. Can you pls advise what I should change to make it work?

anlek commented 7 years ago

Right, I missed that, sorry. It should work with lu_project field id should be referenced under lu_object in project_id. There might be an issue with your lu_object not having a key field (as I update fields after all the tables are setup). Is there a way to use object_id as a key? Maybe you can set it to: column "object_id", :key, as: :string.

You'll have to test on your data to see if it works.

Good luck, Andrew

jcheng418 commented 7 years ago

Thank you Andrew. Let me do a test and let you know. In lu_object collection, object_id is an integer so what does "as:: string" mean?

anlek commented 7 years ago

Hey @jcheng418, I just realized you had a question in your last comment. I reviewed your setup again, and I don't think as: :string is valid for your situation.

Let me know if you got it working or not.