marmelab / ng-admin

Add an AngularJS admin GUI to any RESTful API
http://ng-admin-book.marmelab.com/
MIT License
3.95k stars 725 forks source link

ngRepeat:dupes Duplicate Key in Repeater #1321

Closed ap1969 closed 7 years ago

ap1969 commented 7 years ago

Hi,

I need some help resolving the above error, as it's got me stumped.

The background is: the database contains a list of clients, and a list of notifications each client has received. Each notification has a client_id field which contains the ID of the client that received it. All records have got unique IDs in the _id field for that entity.

Here are the relevant sections of the configs:

var notification = nga.entity('notifications').identifier(nga.field('_id'));
var client = nga.entity('clients').identifier(nga.field('_id'));

        client
            .listView()
            .fields([
                nga.field('email').isDetailLink(true),
                nga.field('_id'),
                nga.field('role'),
            ]);

        client.showView() // a showView displays one entry in full page - allows to display more data than in a a list
            .fields([
                nga.field('_id'),
                nga.field('email'),
                nga.field('role'),
                nga.field('notifications', 'referenced_list')
                    .targetEntity(nga.entity('notifications'))
                    .targetReferenceField('client_id')
                    .targetFields([
                        nga.field('_id').label('ID'),
                        nga.field('title'),
                        nga.field('status')
                    ])

            ]);
        admin.addEntity(client);

I'm getting the error in the client.showView() page. The client ID/Email/Role are shown, and below them, the table is laid out for the notifications which have been sent to that client. But the table is empty and I'm getting the ngrepeat error noted above.

The full error starts with:

Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: entry in entries track by entry.identifierValue, Duplicate key: undefined, Duplicate value: {"_entityName":"notifications","values":{"_id":"589b981291d3a53a9d0fa56b",......

But there are no "undefined" _id fields, so I'm not sure where the undefined is coming from.

I don't think this fits the referenced_list or reference approach, and there is definitely no embedding of the related docs.

Can anyone point in the right direction to get the notifications listed, please?

Thanks in advance, Andy

Kmaschta commented 7 years ago

Hello,

As explained in the README, the GitHub issue tracker is for bugs and enhancement requests. So I close this issue, but feel free to write a question on StackOverflow with the tag ng-admin.

Thanks for using ng-admin!