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

Problems with handling of related fields in EditController _edit(). #36

Open
davidkellerman opened this issue Dec 17, 2017 · 1 comment

Comments

@davidkellerman
Copy link
Contributor

In EditController, the _edit() method calls defaultContext() with the related parameter set to true, which eventually causes _modelAttributes() to try to load related fields.

For cc-assess Project instances, this unfortunately produces a Waterline find() operation that tries to load all the GeoRegion instances, which is a bad thing – they won't fit in memory.

There seem to be problems on multiple levels.

It's not clear that the related entities loaded by _modelAttributes() are ever made accessible. (In my reading of the code, they're assigned to the related variable, but aren't passed back to the caller.

The loading of related entities in ``_modelAttributes()` isn't restricted to the displayed attributes. It tries to load all fields with a relation, whether they're in the display list or not.

@loppear
Copy link
Contributor

loppear commented Dec 18, 2017

  1. Definitely an issue that related record population isn't limited to display attributes or available for explicit restriction. I'd probably rename this issue "EditController unnecessarily populates related attribute instances for non-display attributes"
  2. Related entries are used to show dropdowns on the edit screen (e.g. src/templates/form-inputs/web-form-input-related.ejs), they are filled in as .instances at the bottom of _modelAttributes.

This code is crufty from a long series of additions so there's plenty of possible refactors. Least change would appear to be to filter related as we do attrs to limit it to display fields here: https://github.com/nxus/web/blob/master/src/ViewController.js#L258 slightly more forward looking would be to add an option parameter to the class to specify specifically which attributes to populate instances for (defaulting to all), in case you want to "display" GeoRegions but not pay this get-them-all cost.

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

No branches or pull requests

2 participants