archfirst / joinjs

A JavaScript library to map complex database joins to nested objects.
MIT License
154 stars 19 forks source link

issue with associations from many to many relationship #6

Closed cra-gb closed 8 years ago

cra-gb commented 8 years ago

Hello,

I am having issues with a many to many table relationship where table a and table c are associated by table b. The relationship shouldn't be the issue as I am returned the following information:

 [ anonymous {
    pl_id: 97,
    pl_public_name: 'North',
    pl_identifier: '66143c4a-2c2c-11e6-bd89-0242ac160002',
    ca_id: 201,
    ca_public_name: 'Name 10',
    ca_description: 'Description 10',
    ca_icon: null,
    ca_start_date: 2016-06-06T21:19:48.951Z,
    ca_end_date: 2016-06-11T21:19:48.951Z },
  anonymous {
    pl_id: 98,
    pl_public_name: 'South',
    pl_identifier: '6614645e-2c2c-11e6-bd89-0242ac160002',
    ca_id: 201,
    ca_public_name: 'Name 10',
    ca_description: 'Description 10',
    ca_icon: null,
    ca_start_date: 2016-06-06T21:19:48.951Z,
    ca_end_date: 2016-06-11T21:19:48.951Z },
  anonymous {
    pl_id: 99,
    pl_public_name: 'East',
    pl_identifier: '661464f4-2c2c-11e6-bd89-0242ac160002',
    ca_id: 201,
    ca_public_name: 'Name 10',
    ca_description: 'Description 10',
    ca_icon: null,
    ca_start_date: 2016-06-06T21:19:48.951Z,
    ca_end_date: 2016-06-11T21:19:48.951Z },
  anonymous {
    pl_id: 100,
    pl_public_name: 'West',
    pl_identifier: '66146562-2c2c-11e6-bd89-0242ac160002',
    ca_id: 201,
    ca_public_name: 'Name 10',
    ca_description: 'Description 10',
    ca_icon: null,
    ca_start_date: 2016-06-06T21:19:48.951Z,
    ca_end_date: 2016-06-11T21:19:48.951Z } ]

The maps are as follows

let result_maps = [
                {
                    mapId: 'ca_map',
                    idProperty: 'id',
                    properties: ['public_name', 'description', 'icon', 'start_date', 'end_date'],
                    collections: [
                        {name: 'pl', mapId: 'pl_map', column_prefix: 'pl_'}
                    ]

                },
                {
                    mapId: 'pl_map',
                    idProperty: 'id',
                    properties: ['public_name', 'identifier']
                }
            ];

What I am expecting is

id: 201,
public_name: "Name 10",
description: "Description 10",
icon: null,
start_date: "2016-06-06T21:19:48.951Z",
end_date: "2016-06-11T21:19:48.951Z",
pl: [
{ },
{ },
{ },
{ }
]
}
]

But as you can see the pl array is returning empty objects.

What am I missing?

Thanks.

cra-gb commented 8 years ago

Nevermind. I just realized I had columnPrefix as column_prefix. Too much time spent staring at code.

Sorry for the false alarm!

nareshbhatia commented 8 years ago

No worries :-)