marmelab / ng-admin

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

Problems with the field type "referenced_list" #1090

Closed thiagofalcao closed 8 years ago

thiagofalcao commented 8 years ago

Hi everyone, I have a problem with the field type: "referenced_list". For my project this option it is showing all itens(in my case all places) instead of only the itens that is related with the entity that i'm using the referenced_list. I already see the guide but I think I am doing something wrong, here is the code:

//Show seller seller.showView().title('Show Seller') .fields([ nga.field('name').label('Name'), nga.field('email').label('E-mail'), nga.field('id').label('id'), nga.field('places', 'referenced_list') .targetEntity(admin.getEntity('places')) .targetReferenceField('seller_id') // places.seller_id = seller.id it is not woking for my project .targetFields([ nga.field('seller_seller_id'), nga.field('id') ]) ]);

and here is my JSON //Json "sellers": [ { "id": 3, "createdAt": "CURRENT_TIMESTAMP", "updatedAt": "CURRENT_TIMESTAMP", "name": "titi vendedorINSERT", "email": "titi@vededor.com", "password": 123, "cpf": "0234923432432.234", "admin": 2, "active": true }, places": [ { "id": 2, "cnpj": 12330917234, "name": "Joey's", "opened": true, "phone_number": "(81)3323-12122", "type": "PRODUCT", "place_category_place_category_id": 14, "seller_seller_id": 2, "city": "teste", "zipcode": 5959595959 },

Thanks for the attention.

hobywhan commented 8 years ago

You can use in your showView() an embedded_list Example :

nga.field('places', 'embedded_list')
.targetFields([
  nga.field('seller_seller_id').label($translate.instant('Seller Id')),
  nga.field('id').label($translate.instant('Id'))
])
.label($translate.instant('Campaigns')),

Don't forget code tags

cfatt10 commented 8 years ago

I think your problem is with your .targetReferenceField(). The field you want is 'seller_seller_id', but in your .targetReferenceField() you have 'seller_id'

thiagofalcao commented 8 years ago

Hello guys , thanks for the replies. @hobywhan really wanna do this configuration in the listview. @cfatt10 I used the targetReferenceField correctly , just forgot to update the question. I don't know why but this targetReferenceField seems not work over here.