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

References #158

Open
groenroos opened this issue Mar 25, 2021 · 1 comment
Open

References #158

groenroos opened this issue Mar 25, 2021 · 1 comment
Assignees
Labels
refactoring Drastic code quality improvements

Comments

@groenroos
Copy link
Member

The behaviour around reference fields has become a bit muddy. Go through the entire app and the MongoDB driver to ensure all reference fields behave as advertised, and make sense code-wise.

@groenroos groenroos added the refactoring Drastic code quality improvements label Mar 25, 2021
@groenroos groenroos added this to the M2 - Release 2.0 milestone Mar 25, 2021
@groenroos groenroos self-assigned this Mar 25, 2021
@groenroos
Copy link
Member Author

groenroos commented Mar 14, 2022

General outline of expected functionality:

  • Reference fields should not be implied; they must be explicitly set in the model, complete with the collection they refer to
  • Each field should be able to contain n number of references
    • MongoDB can handle this natively as an array
    • Drivers for less flexible relational databases may need to abstract away a relations table

GET /data

  • In the returned data, each reference should be expanded to the corresponding object
    • There should be a hard limit on how many levels will be expanded (3? 10?)
    • Also a way to detect and prevent recursive references
    • By default, always return an array of objects. Add a single key for the model if the user wants to force a direct object
  • In filtering in URL patterns, only filtering by the stored IDs needs to be supported. CSV of IDs should be treated as an OR

POST /data

  • If the posted value for the reference field is a string, or an array of strings, assume it's an object ID
    • In strict mode, return an error if it's not a valid ID
  • If the posted value is a (JSON) object, or an array of objects, create a new entry based on the values
    • Need to guard against a POST request with multiple reference fields, where the first one succeeds, but the second one fails validation; this should not result in a situation where the overall request fails, but that one straggler entry is retained in the referenced collection
    • Surface a config value for max number of records created on the fly via a reference field, with a sensible default
  • When modifying an existing record, overwrite any existing value with whatever is sent, if it's sent
    • Dropped references should not result in deleted records

DELETE /data

  • Records to be deleted can be filtered the same as above
  • Referenced records should not be deleted automatically

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactoring Drastic code quality improvements
Development

No branches or pull requests

1 participant