Skip to content
This repository has been archived by the owner on Apr 13, 2022. It is now read-only.

Required decorator ignored on properties on child objects #53

Open
friendly-tech opened this issue Feb 27, 2019 · 4 comments
Open

Required decorator ignored on properties on child objects #53

friendly-tech opened this issue Feb 27, 2019 · 4 comments

Comments

@friendly-tech
Copy link
Contributor

The problem

When creating a convector model which has properties which are simple classes, properties decorated with @require() on this child class are ignored.

Details

Having a property on a convector model that points to another class, then on that child class i have a required property - the save does not fail if i do not pass this value in for this property.

See This issue for code setup, just add a Required() attribute to one of the properties on the child class.

@diestrin
Copy link
Contributor

diestrin commented Mar 1, 2019

What's the motivation behind using a class without a ConvectorModel? ConvectorModel is the one providing all this functionality, the decorators are just flags for it.

@friendly-tech
Copy link
Contributor Author

friendly-tech commented Mar 1, 2019

The motivation is, i might be passing in a convector model that has child properties - i don't want these child props to be convector models as makes no sense for them to have a type or id (since they are stored inline with the parent and never accessed anywhere other than via the parent object).

Also, i want to pass in payloads that might not be convector models (into the controller), and from there i might do multiple complex create/update delete of various other convector models - ie not always simple crud - sure i can use convector model but i wont ever store that model so having an id/type seems a bit pointless on it.

Sort of like transactions in composer.

For example

class BulkTransferSomething {
     @Required()
     string ids: Array<string>;

     @Required()
     string to: string;

     @Required()
      somethingElse: string;
}

@diestrin
Copy link
Contributor

diestrin commented Mar 1, 2019

You can still use ConvectorModels for those cases. When you declare an inner property to be FlatConvectorModel<BulkTransferSomething> it will ignore the id and type field in the end result.

As I mentioned, the core logic for validations is inside the ConvectorModel class, if you don't use it, unexpected things might happen.

@friendly-tech
Copy link
Contributor Author

friendly-tech commented Mar 1, 2019

Great i will try that on the inner properties.

Regarding the 'simple object' as a controller method param - can i possibly do something like this FlatConvectorModel<BulkTransferSomething> as a @param() in my controller method.

 @Invokable()
  public async save(@Param(yup.object().shape(whatever...)) 
       arg: FlatConvectorModel<BulkTransferSomething>): Promise<any> {
  }

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

No branches or pull requests

2 participants