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

Same resource nested and un-nested -> double call to auto-load #50

Open
Spiralis opened this issue Feb 12, 2012 · 2 comments
Open

Same resource nested and un-nested -> double call to auto-load #50

Spiralis opened this issue Feb 12, 2012 · 2 comments

Comments

@Spiralis
Copy link

Hi,

I have two resources, Collections and Teams, that I am exposing using express-resource, like this:

var competitions = app.resource("competitions", require('./resources/competitions'));
var teams        = app.resource("teams",        require('./resources/teams'));
competitions.add(teams);

Teams is then a nested resource within it's parent competition, which is as I wanted it to be. However, I also wanted teams to be accessible as it's own resource. In other words, like this:

/competitions/:id/teams/:id
/teams/:id

So, to get this I changed the code as follows:

var competitions = app.resource("competitions", require('./resources/competitions'));
var teams        = app.resource("teams",        require('./resources/teams'));
competitions.add(teams);
teams = app.resource("teams", require('./resources/teams'));

I don't know if this is the way it is supposed to be set up, but this actually works. There is only one small problem. I have an auto-load method setup for the team-resource, and when I access the /teams/:id resource it actually ends up calling the auto-load twice. I guess that somehow it fires for both the teams/.id and the competitions/:id/teams/:id resource?

Any ide on how to avoid this from happening?

@kb19
Copy link

kb19 commented Apr 11, 2013

I ran into this as well. I used the express-resource map function to manually define my non-nested routes . I don't use the auto-load functionality but you could give this method a shot if you're still running into this issue.

tenant.map( 'del', '/:tenant', tenantModule.destroy );
tenant.map( 'get', '/:tenant', tenantModule.show );
tenant.map( 'put', '/:tenant', tenantModule.update );

location.add( tenant );

@wanbok
Copy link

wanbok commented Apr 13, 2013

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants