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 `id` in another table after changing it's format #90

Open ghost opened 8 years ago

ghost commented 8 years ago

I have a users table and an accounts table. I am trying to reference accounts via the acc_id field in the users table and it works fine. My problem is that it applies the pre_mongified_id to the acc_id field in the users table rather than my newly formatted id (I need this for a certain use case).

# Users
table "users" do

  before_save do |row|
    row._id = SecureRandom.hex(17)
    row.emails = [{
      :address  => row.delete('address'),
      :verified => false
    }]
  end

  column "id", :key, :rename_to => "_id", :as => :string
  column "acc_id", :integer, :rename_to => "accountId", :as => :string, :references => "accounts"
  column "address", :string
end
ghost commented 8 years ago

I see this function get_id_using_pre_mongified_id but not 100% sure on where I can use it..

anlek commented 8 years ago

I think you might have found a bug in the system, I don't know if references method listens to :as.

pre_mongified_id is the id of your record in your sql database. I use this to look up your relationships once they've been moved into MongoDB.

I currently can't review this, I have a very busy schedule.

One way you can do it, is leave acc_id as is, and do a post move script (outside of Mongify) to fix the issues it may have caused.

Good luck and sorry I can't help at the moment.

ghost commented 8 years ago

Hi @anlek, firstly, many thanks for this project. It's helped tremendously with our migration so far.

I've decided to retain the original Id's. I do agree with you regarding the references. I understand the process, but I don't think it's ever worked for me, so I'm not even using the references attribute in my migration script. Probably worth looking into when you have the time.