1602/express-on-railway — Issue #104: Integration with mongo-auth and juggling DB's ORM
Author: pctj101
Created: 2012-01-21 17:12:47+00:00
State: open

I've been having a hell of a time trying to integrate mongoose-auth with railway.js while leveraging JugglingDB's ORM.

I think the core of the problem is JugglingDB's handling of the User object. JugglingDB is pretty cool because it puts a lot of ORM convenience methods.

But I think JugglingDB replaces the "User" object that mongoose-auth enhances (mongoose User + mongoose-auth plugin) with a "JugglingDB ORM User Object". So of course all the calls the middleware of mongoose-auth makes to find/create users in mongodb are missing and fail.

For the sake of near insanity there is a: "mongoose-auth User" and a "jugglingDB User". I can't find a pretty way to ensure that the result:

1) Has all the functions from both "mongoose-auth's plugin" and "juggling DB's ORM".
2) Uses the same database connection (is this even a good idea?)

One idea was to try to define a JugglingDB User model then add our plugin:

So in the railway app I did db/schema.js:
var User = describe('User', function () {
property('created_at', Date, {default: Date.now})
});

Then modified railway/lib/models.js to add:
app._schemas = _schemas;

This way I could fish out the mongodb connection from app._schemas[0].client.modelSchemas.User
Then add the plugin as app._schemas[0].client.modelSchemas.User.plugin(mongooseAuth, { ... });

Which I think works. But then JugglingDB simply throws this awesome User class in the trash and puts the JugglingDB ORM version in its place. Sigh....

Anyways... if you have ideas, please let me know. If you feel I'm asking in the wrong place, let me know too. It's an integration issue so it's always difficult to know where to ask.

Thanks!