visionmedia/express-resource — Issue #50: Same resource nested and un-nested -> double call to auto-load
Author: Spiralis
Created: 2012-02-12 15:41:17+00:00
State: open

Hi,

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

```javascript
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:

```javascript
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?