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

Mapping associations with no join included #11

Open
lfreneda opened this issue Feb 9, 2017 · 2 comments
Open

Mapping associations with no join included #11

lfreneda opened this issue Feb 9, 2017 · 2 comments

Comments

@lfreneda
Copy link

lfreneda commented Feb 9, 2017

What If a want to group some properties on a nested object.

Here's a sample:

resultMaps = [
      {
        mapId: 'teamMap',
        idProperty: 'id',
        properties: ['name'],
        associations: [
          { name: 'players', mapId: 'playerMap', columnPrefix: 'player_' }
        ]
      },
      {
        mapId: 'playerMap',
        properties: ['name']
      }
    ]

    resultSet = [
      { team_id: 1, team_name: 'New England Patriots', player_name: 'Tom Brady' }
    ];

    mappedResult = joinjs.map(resultSet, resultMaps, 'teamMap', 'team_');

    expect(mappedResult).to.deep.equal [
      {
        id: 1
        name: 'New England Patriots'
        player: {
          name: 'Tom Brady'
        }
      }
    ]

Is this possible?

@FerrielMelarpis
Copy link
Contributor

probably create custom property for that using createNew

@FerrielMelarpis
Copy link
Contributor

@lfreneda actually disregard my comment above.
The most likely solution for this would be to use player_name as idProperty of playerMap. There would be no problem with doing that if player_name is a unique column and assuming that this is a one-to-one relationship since you are asking about associations, not collections.

    resultMaps = [
      {
        mapId: 'teamMap',
        idProperty: 'id',
        properties: ['name'],
        associations: [ // use collections for one-to-many
          { name: 'players', mapId: 'playerMap', columnPrefix: 'player_' }
        ]
      },
      {
        mapId: 'playerMap',
        idProperty: ['name']
      }
    ];

However, with regards to the PR title:

Mapping associations with no join included

I think that that is not the scope of this library. Associations are basically the way to map relationships in result sets. join-js is agnostic of your data relationships that is why you are the one to teach it how to read your data.

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

2 participants