marmelab / ng-admin

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

In "creationView" I can't use two fields of type "reference" related to the same entity. #765

Open vcenturion opened 9 years ago

vcenturion commented 9 years ago

In "creationView" I can't use two fields of type "reference" related to the same entity. If I use two fields the data is duplicated in the select input, if I used three fields the data are tripled, and so on.

Entity Wallet:

"wallets": [{
    "id": 1,
    "currency": "ZZ",
    "owner": 1,
    "balance": "123123",
    "country": "ASD",
    "modification": "2015-10-13T15:20:43.366371Z",
    "creation": "2015-10-13T15:20:43.366371Z"
}]

"charges": [{
    ...
    "source_wallet": 5
    "beneficiary_wallet": 8
    ...
}]

The Create View

charges.creationView()
    .title('Create new Charge')
    .fields([
        ...
        nga.field('source_wallet', 'reference')
            .label('Source Wallet')
            .targetEntity(admin.getEntity('wallets'))
            .targetField(nga.field('id'))
            .singleApiCall(ids => ({ 'id': ids })),
        nga.field('beneficiary_wallet', 'reference')
            .label('Beneficiary Wallet')
            .targetEntity(admin.getEntity('wallets'))
            .targetField(nga.field('id'))
            .singleApiCall(ids => ({ 'id': ids })),
        ...
    ]);
vcenturion commented 9 years ago

Anybody can help me about this? Is there something I'm doing wrong?

Thanks

huvber commented 9 years ago

I also have the same problem

kinnrot commented 9 years ago

+1

ace-han commented 9 years ago

I also have the same problem. +1

maximk-1 commented 8 years ago

+1 the same =(

kane-chen commented 8 years ago

+1 the same problem

orgito commented 8 years ago

+1 My workaround for that is to create different variables to use as reference in .targetEntity().

...
var usera = nga.entity('users');
var userb = nga.entity('users');
...
nga.field('usera_id', 'reference').targetEntity(usera),
nga.field('userb_id', 'reference').targetEntity(userb),
...

I even use .permanentFilters() to show different values for each field.

kane-chen commented 8 years ago

i use diff-entity to resove it, detail: [https://github.com/kane-chen/mview/blob/master/mview.adminui/src/main/webapp/admin/js/app1/definitions/widgets.js] like:
defines:

    var template_css = nga.entity('templates/type/css').identifier(nga.field('vkey'));
    admin.addEntity(template_css);
    var template_js = nga.entity('templates/type/js').identifier(nga.field('vkey'));
    admin.addEntity(template_js);
    ......
     use:
     ----------------------------------------------------------------------------------------------
      nga.field('cssDefKey','reference').label('cssDefinition')
            .targetEntity(admin.getEntity('templates/type/css'))
            .targetField(nga.field('vkey'))
        .validation({required:true})
            .perPage(10),
  nga.field('jsDefKey','reference').label('jsDefinition')
            .targetEntity(admin.getEntity('templates/type/js'))
            .targetField(nga.field('vkey'))
            .perPage(10),
jotadepicas commented 8 years ago

+1 Facing the same issue.

yogipatel commented 8 years ago

👍