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
315 stars 81 forks source link

Can mongify do `has and belongs to many`? #50

Open etodanik opened 9 years ago

etodanik commented 9 years ago

I'm trying to migrate a database that among other things has a has and belongs to many relationship.

Basically, I have a users table, a roles table, and a roles_users table that has user_id and role_id.

Can I easily embed role into user?

anlek commented 9 years ago

Unfortunately it does not. I'm looking at supporting it in a future version of Mongify.

etodanik commented 9 years ago

Is there anything I can do to help? Would you accept a Pull Request? If so - give me kind of a 101 on your project structure, and where you'd be implementing a HABT support structure.

anlek commented 9 years ago

Yes, I would gladly accept pull requests. As for a 101 of project structure, it's pretty straight forward, if you start looking at https://github.com/anlek/mongify/blob/master/lib/mongify/translation/process.rb and processor_common.rb. That's where all the magic happens ;)

DaanGeurts commented 8 years ago

@anlek is this feature request still open?

anlek commented 8 years ago

Yes, unfortunately I haven't had much time to work on Mongify (outside of small updates).

DaanGeurts commented 8 years ago

Thanks for your work so far! Maybe i have some time to start the implementation.

rot26 commented 8 years ago

Hi @anlek et al,

Does anyone have a suggested work-around for many-to-many relationships with mongify?

Using the example above, and assuming users and roles should become separate documents in mongo, you would need to create both to get the mongo id.

In other words, is there a way I can add roles to the user object like so:

user: {
    roles: [
        {role_id: 'aaaaa...aaa01'},
        {role_id: 'aaaaa...aaa02'}
    ]
}
anlek commented 8 years ago

@rot26, I don't think you can do this with the way Mongify works. There would have to be a after_save to make this work. I'm currently swamped with work but I am hoping to re-write mongify so that it will allow you more flexibility but at the moment, it's just not possible.

You can try playing around with before save and see if you can figure out a way to copy the old DB id into role_id and somehow update it afterwards. However, this is outside of the scope of help I can provide here.

MURL1DHAR commented 7 years ago

any updates on many-to-many relationships with mongify?

anlek commented 7 years ago

Sorry, I've been swamped and have no time to dedicate to this. But will gladly review PR from anyone.

Take care, Andrew