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

Use "ReferencedList" with a returned array #241

Closed
Xennis opened this issue Jan 16, 2015 · 11 comments
Closed

Use "ReferencedList" with a returned array #241

Xennis opened this issue Jan 16, 2015 · 11 comments

Comments

@Xennis
Copy link
Contributor

Xennis commented Jan 16, 2015

For instance a request to http://localhost:3000/api/companies/65 returns

{
  "id": 65,
  "name": "Example Company",
  "employees": [
    {"id": 1, "name": "XY", "age": 25, ... },
    {"id": 3, "name": "YY", "age": 28, ... },
    ...
  ]
}

How can I use the returned employees array in combination with the field type ReferencedList (without making an extra API call, the returned array already contains all data)? Hence I want to use something like:

var company = new Entity('companies');

company.showView().fields([
  new Field('name'),
  new ReferencedList('employees')
    //.targetEntity(employees)
    //.targetReferenceField('id')
    .targetFields([
       new Field('name'),
       new Field('age')
    ]); 
]);

Or if it doesn't work in combination with ReferencedList, how can I handle arrays like above instead?

@endel
Copy link
Contributor

endel commented Jan 16, 2015

Our API can return nested related models too. It would be nice to have this option for this when calling singleApiCall, or something.

@lostb1t
Copy link

lostb1t commented Jan 16, 2015

Same here, heavily based on nested relations. This also applies to the other relation methods, ReferenceMany etc

@fzaninotto
Copy link
Member

Great idea, this is something that singleAPICall should allow in the future.

@cvlmtg
Copy link

cvlmtg commented Jan 31, 2015

+1 for this feature.

@fzaninotto
Copy link
Member

I believe this implies the creation of a new type, something like embedded_list. Until this is added to the core, you can still write it yourself, or use the json type.

@Phocea
Copy link
Contributor

Phocea commented Sep 7, 2015

Merci Francois!
This is exactly what I require. Indeed the json type gives me a quick workaround for now.

Please bear in mind that this kind of nesting can even go deeper. Something like:

{
"id": 65,
"name": "Example Company",
"employeeSet": [
{"region": "France",
"employees": [
{"id": 1, "name": "XY", "age": 25, ... },
{"id": 3, "name": "YY", "age": 28, ... }
]},
{"region": "US",
"employees": [
{"id": 6, "name": "XY", "age": 29, ... },
{"id": 8, "name": "YY", "age": 31, ... }
]}
]
}

@devguf
Copy link

devguf commented Sep 13, 2015

+1

@SaiNageswarS
Copy link

+1

1 similar comment
@AlexH7
Copy link

AlexH7 commented Sep 22, 2015

+1

@Phocea
Copy link
Contributor

Phocea commented Sep 24, 2015

I have investigated this project https://github.com/jdorn/json-editor in order to go from a json to an html editor. Just thought I would post this here as it could be of great help toward a custom json / metadata editor

@fzaninotto
Copy link
Member

Fixed by #714

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

9 participants