Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

embedded_list reference fields do not work #786

Open
jamespsterling opened this issue Nov 13, 2015 · 20 comments
Open

embedded_list reference fields do not work #786

jamespsterling opened this issue Nov 13, 2015 · 20 comments

Comments

@jamespsterling
Copy link

I have an edit view with an embedded list field that has sub-fields of reference type and they do not work properly. There is no call to the rest api asking for the list in this example.

        nga.field('editResultsId', 'embedded_list')
            .label('Edit Results')
            .targetFields([
                nga.field('fileSystemId', 'reference')
                    .label('File System')
                    .targetEntity(file)
                    .targetField(nga.field('name'))
                    .validation({ required: true }),
@fzaninotto
Copy link
Member

Hi, which version of ng-admin are you using? This has been added to 0.9.

@jamespsterling
Copy link
Author

I'm using 0.9, just did a fresh pull too

@jamespsterling
Copy link
Author

For clarification, it's the fileSystem reference child on this embedded list entity that does not populate. is this a bug?

@fzaninotto
Copy link
Member

Ah ok, now I get it: it's the file dropdown that is empty, is that it? Then it's just not implemented yet.

@jamespsterling
Copy link
Author

Yes, that's the issue.

@clems71
Copy link

clems71 commented Jan 19, 2016

+1 would be very helpful indeed!

@xteron
Copy link

xteron commented Mar 1, 2016

Just stumbled over the same problem with reference_many inside a embedded_list.

@NadavK
Copy link

NadavK commented Mar 6, 2016

I am not sure this is the same problem.
I am trying to reference a object with nested ids.
Maybe someone can help?

Object with nested references:

{"user":
  "id": 1,
  "orders": [
    {"order_id: 100},
    {"order_id": 101}
  ]
}

The code below returns the following error

(state change error: e.targetField(...).name is not a function)

user.showView().fields([
    nga.field('orders.id', 'reference_many')
          .targetEntity(order)
          .targetField('id')
]);

(BTW, great project! Having an admin tool that works against the backend-logic instead of directly to the DB is truly cool).

@mosasiru
Copy link

+1 seriously need!
is there any workaround?

@collinforrester
Copy link

@NadavK I don't have a solution for the opened issue (which I also need solved). But your error is because you don't have targetField('id') in a field definition: targetField(nga.field('id')) I think.

@MaxTwentythree
Copy link

+1 need it too, would be really great :)

@dowlingw
Copy link
Contributor

dowlingw commented Jul 7, 2016

Some notes from my duplicate over at #1145 (sorry, closed now!)

I can confirm this is still an issue in 1.0.0-alpha4

  1. showView does not perform any retrievals of reference objects for rendering
  2. creationView and editionView both load listings and perform remote completion as expected
  3. editionView does not retrieve the reference object for rendering. However if the object is returned in the listing of objects used to render the dropdown, this does work as expected.

@dowlingw
Copy link
Contributor

dowlingw commented Jul 7, 2016

I had a quick look at this today but wasn't able to make much progress - had to figure out how things hang together. Leaving some notes as @etdev was keen to look at this also.

Crud/routing.js creates a bunch of ui-router resolve definitions based on the model coming out of the admin-config library.

It looks like lib/Utils/ReferenceExtractor in admin-config is the culprit, it only looks at the top level object and doesn't traverse complex fields.

Took a quick stab at fixing this but I've run out of time to look at it this week and it doesn't work.
Here's the code so far, it's a recursive function to find all the reference fields during a call to getReferences.

let find_references = function(fields, recurse_func) {
    let result = new Array();

    fields.forEach(function(field, idx) {
        if( field.type() === 'reference' || f.type() === 'reference_many' ) {
            result.push(field);
        } else if( field.type() === 'embedded_list' ) {
            result.push( recurse_func( field.fields(), recurse_func ) );
        }
    });

    return result;
};
let references = find_references(fields,find_references);

Cheers :)

@underdoeg
Copy link

Any news on this? I ran into the same issue...

@huiyiqun
Copy link

Same problem.

It seems that the referenced entity is not requested according to the Network tab of chrome Developer tool.

@jbrownD3
Copy link

jbrownD3 commented Nov 22, 2016

WORKAROUND -- While waiting for the pull-request to be completed, I found an easy workaround. Just add the same reference field to your top level object (make it hidden, non-editable, not required). As long as you use the same object in .targetEntity() in both the top level and embedded, you will get a populated list. Below I just used an empty label and non-editable field, but you can use CSS to hide the field row as well.

`
var wtEntity = nga.entity('webapp_templates');
var embeddedFields = [
        nga.field('webapp_template', 'reference')
            .targetEntity(wtEntity)
            .validation({required: true})
            .targetField(nga.field('context_name'))
            .detailLinkRoute('show'),
        ...  //Other embedded fields
];
var parentFields = [
        nga.field('webapps', 'embedded_list')
            .targetFields(embeddedWebappsFields),
    ...  //Other parent fields
        nga.field('webapp_template', 'reference')   //Workaround for reference in embedded list
            .targetEntity(wtEntity)  //Same entity object, not just another entity with the same name
            .editable(false)  //non-editable keeps the control from showing
            .label('')  //no label
            .validation({required: false})  //not required so it won't error
            .targetField(nga.field('context_name')),  //not sure this is needed, but I left it
];

`

@DerekK19
Copy link

DerekK19 commented Mar 6, 2017

I found a further problem with reference fields. I followed jbrownD's instructions and they worked great. However I found if I have a bad reference (e.g I have web app templates 1,2,3 but I have a reference to template 4) I get empty lists for all the dropdown lists on my page (even the "good" ones) and I get a traceback:
Error: undefined is not an object (evaluating 'e.values')
http://localhost:3000/asset/ng-admin.min.js:15:14427
It's easily resolved by making sure there are no referential integrity issues in the data, but it's one thing to look out for

@matheo
Copy link
Contributor

matheo commented Mar 9, 2017

This just worked for me:

nga.field('products', 'embedded_list')
        .label('Product in Discount')
        .targetFields([
          nga.field('product', 'reference')
            .label('Product')
            .targetEntity(admin.getEntity('products'))
            .targetField(nga.field('name'))
            .singleApiCall(ids => ({'_id': ids }))
            .remoteComplete(true),

The singleApiCall can be ommited I think, because it's just for MongoDB.

@mosasiru
Copy link

mosasiru commented Mar 9, 2017

I tried to fix it by this PR marmelab/admin-config#75

@vinhtd2
Copy link

vinhtd2 commented Apr 23, 2019

is there any solution for this issue ??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests