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

Add get${relationName} methods to model #13

Closed
radmen opened this issue May 11, 2020 · 2 comments
Closed

Add get${relationName} methods to model #13

radmen opened this issue May 11, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@radmen
Copy link
Contributor

radmen commented May 11, 2020

const User = kex.createModel('User', {
  relations: {
    messages: new HasMany('Message')
  }
})

This would generate the getMessages(id) method which generates a query to the Message model with corresponding WHERE statement.

@radmen radmen added the enhancement New feature or request label May 11, 2020
@radmen
Copy link
Contributor Author

radmen commented May 12, 2020

The idea evolved a little.

Instead of getter methods, create a query method, bound only to model (not query builder).

Something like this:

await User.messages(userId) // here you can start chaining query builder methods for the related query

It seems to be more consistent with other methods.

One thing though, to avoid the risk of method collisions (with scopes) I think that the scopes proxy should be removed. They should be available only when using the query builder.

@radmen
Copy link
Contributor Author

radmen commented May 12, 2020

I started working on this one and bumped into an issue with the way how queries are built and what they're returning. This is a case mostly for BelongsToMany which joins the pivot table and selects the foreign key from that table.

I'd like to avoid adding unnecessary data to the results, however, this can't be done in a decent way for this feature. I decided to wait a moment and rethink the architecture for this. Quite possibly, I should finish #5 first.

@radmen radmen closed this as completed in f5c9c5b May 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant