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

reference_many: TypeError: Cannot read property 'identifierValue' of undefined #1311

Closed matheo closed 7 years ago

matheo commented 7 years ago

Scope

reference_may field throwing an exception following the documentation example. I'm using ng-admin 1.0.0

Description

I'm setting up an Array Of Foreign Keys on my Services entity, to edit the related Subservices, but the edition form is throwing a weird error. I'm using the following form for my service:

  service.identifier(nga.field('_id'));
  service.editionView()
    .title('Edit a Service')
    .fields([
      nga.field('name'),
      nga.field('description', 'text'),
      nga.field('subservices', 'reference_many')
      .targetEntity(nga.entity('subservices'))
      .targetField(nga.field('name'))
      .singleApiCall(ids => ({'_id': ids })),
    ]);

My MongoDB _ids works ok in the panel in general, but this field type is throwing:

TypeError: Cannot read property 'identifierValue' of undefined
    at http://localhost:31227/ng-admin/ng-admin.min.js:47:831
    at Array.filter (native)
    at http://localhost:31227/ng-admin/ng-admin.min.js:47:804
    at Array.map (native)
    at i (http://localhost:31227/ng-admin/ng-admin.min.js:47:780)
    at Object.link (http://localhost:31227/ng-admin/ng-admin.min.js:47:1352)
    at http://localhost:31227/ng-admin/ng-admin.min.js:6:14391
    at http://localhost:31227/ng-admin/ng-admin.min.js:7:16776
    at be (http://localhost:31227/ng-admin/ng-admin.min.js:7:16833)
    at p (http://localhost:31227/ng-admin/ng-admin.min.js:7:9401) <ma-reference-many-field field="::field" value="value" datastore="::datastore" class="ng-isolate-scope">

I see that loading the form, the main entity (service) is GETted but also a list of my subservices GET /rest/subservices?limit=30&skip=0 (cache I think?), then there's a query of the related subservices (or multiple queries if singleApiCall is used, but then comes the exception handling the identifiers :(

Steps to Reproduce

I tried to build my App to see if there was a better trace of the error with no joy, I'm thinking that it has something to do with the "_id" that is not being usedd from the configuration.

Any tips are really appreciated!

matheo commented 7 years ago

For the record, the error is triggered at maReferenceManyFields.js line 20

I've added the .remoteComplete(true) option with no joy. The related entries are queried but the error persist. A problem with the dataStore?

In another entity I have a embedded_list not being filled properly either, the select options are loaded tho, but I cannot select any, a binding problem I think.

matheo commented 7 years ago

Nevermind... my mistake was this line:

.targetEntity(nga.entity('subservices'))

which had to be:

.targetEntity(admin.getEntity('subservicios'))