Comments (11)
@Nexbit Hello again :) Looking at the code, I don't think this makes sense. .find() is a public method used to fetch (find) data for a specific resource. If (for instance) you want to get the delegates you have a couple options:
Association:
entity.find('user').then(user => {
// you can use `user.delegates` if you set up the association in the entity
});
Repository:
class MyRepository extends Repository {
findDelegates() {
return this.findPath(`${this.resource}/delegates`);
}
}
The repository way is a custom implementation. This has been kept open to allow flexibility. Therefor, I'd say no to refactoring find() (which has a very specific purpose).
Something like this could work, but is a breaking change:
findPath(path, criteria, raw) {
if (path[0] !== '/') {
path = `${this.resource}/${path}`;
}
}
This follows the convention of absolute and relative paths. I'd need a vote on this though.
from aurelia-orm.
@RWOverdijk I agree with your reasoning, and maybe the findPath
refactoring you suggest could be added in the next major version.
from aurelia-orm.
just to make sure: you do know that criteria is used as part of the path if it is a number or string only?
so, find(1) translates to eg api/users/1
or findPath('users',1) to api/users/1
from aurelia-orm.
@doktordirk Yeah I used that to retrieve single resources directly, but my original issue was with findPath
when retrieving a related resource like orders/1/items
, as described in the comment I pointed out in my first post.
I know that libraries like sails or loopback are more plain, given that they are auto-generated for the most part, but other hand-crafted apis can make good use of sub-resources (without abusing it, or it will result in a nesting nightmare).
from aurelia-orm.
so you.d need a entity.find then?
from aurelia-orm.
I think it would be nice to have a repository method similar to .findPath(), but .call(). Same parameters, but it would call an action on top of the root path.
In other words a User repository would call "user/list/1" for .call("list",1).
I really need this for ASPNetCore where the Controller is "user" but it typically takes an action name as well.
call(path:string, criteria:any) {
let fullPath = this.getResource() + "/" + path;
return this.findPath(fullPath, criteria);
}
I think this is the same issue that @Nexbit was having.
from aurelia-orm.
If it does exactly the same, you can just extend it in your application.
from aurelia-orm.
@RWOverdijk Ok. I actually tried to extend it, but I am missing something in how I set it up.
I Subclassed Repository to AppRespository.
Then then set it as the Repository using the decorator on the Contact Entity Type.
import {AppRepository} from 'repository/app-repository';
@repository(CustomRepository)
...
But then when I attempted to get an instance in the viewmodel:
entityManager.getRepository('contact');
It returned a regular repository, not an AppRepository so I could call my custom methods.
Am I doing something wrong in the wireup?
from aurelia-orm.
@gregoryagu Did you specify the @resource on the entity as 'contact'?
Also, it should be possible to overwrite the default repository. Simply register your custom repository as Repository
on DI.
from aurelia-orm.
Closing this due to inactivity. Feel free to reopen if this question still exists :)
from aurelia-orm.
Yes, this was resolved. Sorry, forgot to update this. Thanks very much.
from aurelia-orm.
Related Issues (20)
- Add view-manager HOT 3
- Issue with latest webpack skeleton HOT 3
- Null float entity field converts to NaN on client HOT 1
- Method `getNewIdentity` won't check if identifier decorator is used
- Implement lazy-loaded association
- Allow configuring/using FetchClient in aurelia-api HOT 2
- entityManager.getEntity not working with string in production mode HOT 1
- TypeError: Cannot read property 'name' of undefined HOT 2
- Registering an entity without the @resource() decorator leads to invalid meta data HOT 5
- EntityManager fails to return DefaultRepository if repository class is undefined HOT 3
- Unable to create new entity: Cannot read property 'id' of null
- Question: How to use path parameters? HOT 3
- Possible to auto-generate Aurelia ORM definition from Django model? HOT 1
- Sending parameters as path separated with "/" HOT 1
- Validation Rules Not Running
- Updating Related Items HOT 2
- Endpoint decoration dont seems to work HOT 4
- Still Active or? HOT 2
- Nullable Date Support with @type decorator HOT 1
- Initializing the Repository. HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aurelia-orm.