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

Close the loop with relations #311

Closed
neumino opened this issue Aug 11, 2015 · 5 comments
Closed

Close the loop with relations #311

neumino opened this issue Aug 11, 2015 · 5 comments

Comments

@neumino
Copy link
Owner

neumino commented Aug 11, 2015

Thinky was designed to work well with saved relations.

People sometimes just want to just save a relation. This leads to multiple issues like #29, #245, #309 etc.

I'll add a method addRelation and removeRelation that will update only relations. The expectation being that all the documents exists, only the relation is missing.

API:

Query.prototype.addRelation(field, joinedDocument);
  • for hasOne and hasMany, the primary key of joinedDocument is required
  • for belongsTo, the primary key or the joined field of joinedDocument is required
  • for hasAndBelongsToMany, the primary key or the joined field of joinedDocument is required

The last constraint will be for v1 that Query must return a document so the query is probably something like model.get(<x>)

Query.prototype.removeRelation(field[, joinedDocument])
  • for hasOne and belongsTo, joinedDocument is not needed
  • for hasMany and hasAndBelongsToMany, if joinedDocument is not provided, all relations will be removed

Same constraint as for addRelation, query must return a document.

@neumino
Copy link
Owner Author

neumino commented Aug 13, 2015

In 2.1.1

@esatterwhite
Copy link

@neumino Could you add this explaination to the documentation w/ an example. Would be very helpful.

Thanks.

@neumino
Copy link
Owner Author

neumino commented Aug 9, 2016

The tests have a few examples
https://github.com/neumino/thinky/blob/master/test/query.js#L832

I'll try to add them on the website.

@esatterwhite
Copy link

addRelation doesn't seem too be on the Document class either. removeRelation is there.

@neumino
Copy link
Owner Author

neumino commented Aug 15, 2016

Added in 2.3.5

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