Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Schema constructor so that it picks up config values for the lounge object. #5

Open
bojand opened this issue Jan 8, 2016 · 6 comments
Assignees

Comments

@bojand
Copy link
Contributor

bojand commented Jan 8, 2016

Right now when we do:

var schema = new lounge.Schema(...);

The config settings set in the lounge instance do not get applied to the constructor. We should be able to do this, so that config settings are applied.

@waffledonkey
Copy link

Would this set expiry for both the document and the reference? Currently it seems to set expiry you have to do so at the model as part of save() but the references don't get a similar expiry so the document disappears and the references linger. :(

@bojand
Copy link
Contributor Author

bojand commented May 16, 2017

Hello, thanks for your comment. Can you elaborate some more on the use case and maybe provide some sample code. Not sure if it is this issue, but could be a different issue or missed feature.

@waffledonkey
Copy link

waffledonkey commented May 16, 2017

Sure; and my apologies in advance if this belongs elsewhere. Yours is the only ODM that seems to support expiry; which I need. ☹️

var schema = lounge.schema({
    id: {
        type: String,
        key: true,
        generate: false,
        refKeyCase: 'lower'
    },
    manufacturer: {
        type: String, 
        index: true
    },
    type: String,
    sku: {
        invisible: true,
        type: 'alias',
        target: 'id'
    }
}, {expiry: 60});
// setting expiry here has no effect on either the resulting model instances or their refs

schema.pre('save', function (next) {
    this.type = this.modelName;
    next();
});

var sku = new Sku({
    id: 'sku8260387',
});

// setting expiry here will delete the model after 60 seconds, but the ref will remain indefinitely
sku.save({expiry:60}, function (err, result) {  
    if (err) throw err;
    console.log(result);
});

@bojand
Copy link
Contributor Author

bojand commented May 16, 2017

Ok yes this is a missing feature (and possibly a bug). we can add something like saveOptions to the schema options that can specify expiry, persist_to and replicate_to options, that would be then used globally for all instances of that model / schema. Will try and add this soon.

Can you explain in more detail the schema and the intention of that schema, as it's not clear to me. What do you mean by ref?

@waffledonkey
Copy link

the schema was mostly a goof just to compare lounge to competing ODM libraries before I got too far down the path (no offense).

I understand your confusion with "ref"... I didn't think about it at the time, but I stripped the schema down to the bare essentials to demonstrate the expiry issue and in doing so removed the indexed properties that would normally automatically create reference documents. I edited the previous comment to add one back ("manufacturer").

In this scenario, the persisted Sku model instance will expire and be purged from couchbase, but the reference document $_ref_by_manufacturer_<name> will stick around even though the document it references is no longer present.

@bojand
Copy link
Contributor Author

bojand commented May 17, 2017

Hello I have added 2 issues related to this. One is a bug, #65, and one is a feature, #66. Please continue any relevant discussion there. Thanks.

@bojand bojand self-assigned this Apr 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants