-
Notifications
You must be signed in to change notification settings - Fork 115
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
[question] Associations, criterias and milestones API #85
Comments
Howdy, hopefully these answer your questions a bit:
Any help with the documentation effort is most welcome! |
@mbroadst Hi, Matt, thanks for fast response. I'll check it out and come back with the feedback later today, |
It might be worth noting that for milestones: if a milestone isn't set (e.g. resource.fetch hasn't been declared by default in the controller, or by you), then the |
@mbroadst About second question
// user.js
User('...', {
classMethods: {
associate: function(models) {
User.hasMany(models.Folder, {
onDelete: 'cascade',
hooks: true
});
... // api.js
var users = epilogue.resource({
model : db.User,
associations: [db.Folder],
endpoints : ['/api/v0/users', '/api/v0/users/:id']
});
users.use(require('./users/users.js')) Trying: curl http://192.168.59.103:8089/api/v0/users/5/folders
I suppose, I'd doing something wrong. Could you point me the right direction? Thanks you for your help. |
@f1nnix we don't have docs written up for auto-association yet, but you can take a look at the tests for how we've been using it. You would specify:
and it should automatically associate everything for you (that's already defined as an association through Sequelize definitions) |
@f1nnix Try |
var users = epilogue.resource({
model : db.User,
associations: true,
endpoints : ['/api/v0/users', '/api/v0/users/:id']
});
{
"message": "Not Found",
"error": {
"status": 404
},
...
} To ensure, Folder is associated to User, let's try to include it into root node request: var users = epilogue.resource({
model : db.User,
include : [db.Folder],
associations: true,
endpoints : ['/api/v0/users', '/api/v0/users/:id']
});
{
"id": 5,
"email": "john@doe.com",
"hash": "...",
"Folders": [
{
"id": 5,
"title": "untitled",
"UserId": 5,
...
}
]
} |
Looked through the tests, hmm. Code looks the same at first look. Still digging... Thanks, guys. I'll come back soon, if I find the problem. |
@f1nnix try not specifying the end points (these will be overridden anyway with auto associations). you can still specify a base URL for all of them (/api/v0 in this case). Also there are very likely issues with pluralization, though I tried to make some safe guesses, so mess around with "folder" vs "folders" etc. Sorry for the trouble, this is still an incomplete feature :) |
@mbroadst I've finally made it to work. Not sure what was the problem, but after rebuilding all the dev environment and specifying
in package.json, and then My settings (as you suggested): epilogue.initialize({
app: app,
sequelize: db.sequelize,
base: '/api/v0'
});
var users = epilogue.resource({
model: db.User,
associations: true
}); Now: curl http://192.168.59.103:8089/api/v0/users/2/folders [
{
"id": 1,
"title": "untitled",
...
}
] However, I've noticed, that for request to root note (User), Folder is also populated: curl http://192.168.59.103:8089/api/v0/users/ [
{
"id": 2,
"email": "...",
"hash": null,
...
"Folders": [
{
"id": 1,
"title": "untitled",
...
"UserId": 2
}
]
}
] Is it supposed behavour? IMHO, it's not quite correct to auto-populate associations. In fact Anyway, it's working now. Thank you for your work! |
BTW,
Are all CRUD actions created for associated models? Can I create folder for user, performing POST to According to tests, only read and list actions are supported at this moment. If I'm right, do you have any plans to implement others? Thanks. |
@f1nnix you'll probably want to do a quick read over this issue: #34, where this feature was discussed at length. You'll see that @Fridus only continued my work to finish off support for read (and list on a few) operations on associated routes. In fact, the add/update case is non-trivially more complicated and it seems few people have the time needed to implement it :) As for |
@mbroadst I'm considering a PR to add an option (or change the behavior) of resource with associations. I also don't think it is correct to return a resource and its associations when the primary resource endpoints are called without specifying an association. In a typical use case where we have users and projects, |
@sdebionne yes certainly still interested in help with the module, please open up a new issue with your proposed changes so there can be some discussion about it. The root of this problem is that many different frameworks do this differently, and we find ourselves with people using this module from all of them - there needs to be compromise at some point 😄 |
Hi, guys,
thank you for aweseome lib! I've recently started to play with epilogue, got some questions.
I've got two models: User and Folder. User.hasMany(Folder). So:
1. Auto-associations?
Let's test:
curl http://192.168.59.103:8089/users/5/
curl http://192.168.59.103:8089/users/5/folders/
How to make epilogue handle related associations, but not to include them while ordinary request? I mean, I've tried
{ accociations: [db.Folder] }
and
{ include: [db.Folder] }
but epilogue includes [Folders] even in request to User node (
/users/5
). Instead if this I'd like epilogue to handle/users/5/folders
,/users/5/folders/:id
2. Incorrect where attributes
My API provides aliases for id. /users/me/ === /users/5, if current user's ID is 5. So, I've tried such approach:
Not working. Any ideas?
3. Milestones API?
It seems midlestones API is a bit messy right now. Some snippets points for
Some — without
before
node:Which is the proper way to use it? Which hooks are invoked for which controller? Any actual docs or the best option is to check the source?
BTW, I would be happy to help with docs as soon as I get this to work as expected myself :) Very helpful lib, just what I needed.
The text was updated successfully, but these errors were encountered: