-
-
Notifications
You must be signed in to change notification settings - Fork 286
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
IgnoreProperty Decorator problem when inheriting from parent model #503
Comments
// Update export class PropertyRegistry {
....
static getProperties(target: Type<any>): Map<string | symbol, PropertyMetadata> {
const map = new Map<string | symbol, PropertyMetadata>();
ancestorsOf(target).forEach(klass => {
this.getOwnProperties(klass).forEach((v: PropertyMetadata, k: string | symbol) => {
if (!v.ignoreProperty) {
map.set(k, v);
}
});
});
return map;
}
} Not sure if it is intended, but if ancestor class has the property without ignoreProperty flag set, then it gets added to the map, but is not removed if child class has the same property with ignoreProperty flag set to true. I locally made a test and two options worked if (!v.ignoreProperty) {
map.set(k, v);
} else {
map.delete(k);
} Problem with this approach is that now, if parent class will have IgnoreProperty set to true, but the child class won't, then the property will still get added to the map Option 2) Keep a list of ignored properties and skip them static getProperties(target: Type<any>): Map<string | symbol, PropertyMetadata> {
const map = new Map<string | symbol, PropertyMetadata>();
const ignored: string[] = [];
ancestorsOf(target).forEach(klass => {
this.getOwnProperties(klass).forEach((v: PropertyMetadata, k: string | symbol) => {
if (ignored.indexOf(k) !== -1){
return;
}
if (!v.ignoreProperty) {
map.set(k, v);
} else {
map.delete(k);
ignored.push(k);
}
});
});
return map;
} |
Hello @engpire1991 PropertyMetadata: /**
*
* @returns {boolean}
*/
get ignoreProperty(): boolean {
return this.store.get("ignorePropety");
}
/**
*
* @param {boolean} value
*/
set ignoreProperty(value: boolean) {
this.store.set("ignorePropety", value)
} Tell if it works :) |
Hello @Romakita I tried updating PropertyMetadata, but still got the same results. i added some debug logs and here is what i get @ModelStrict(true)
export class UserProductPostModel extends Product{
@Required()
name: string;
@IgnoreProperty()
@Test()
categoryId: number;
@Property()
description: string;
}
function Test(): Function {
return (target: any, propertyKey: string) => {
setTimeout(() => {
console.log(Store.from(target, "categoryId"));
console.log(PropertyRegistry.getProperties(target));
}, 1000);
}
}
// In PropertyRegistry
if (!v.ignoreProperty) {
map.set(k, v);
console.log(`setting property on ${v.targetName} property ${v.name} for ${getClass(target)}`);
} else {
console.log(`ignoring property on ${v.targetName} property ${v.name} for ${getClass(target)}`);
} after the timeout it logs out:
So the 'ignoreProperty' is correctly set in the Store. The property gets correctly ignored on UserProductPostModel model, but is instead taken from the base Product model. |
Fixed with v5.1.1 :) |
Great, thank you :) |
Information
Description
IgnoreProperty decorator is not working when model class inherits a base class with Property decorator set.
Other decorators, for example Required, work correctly on the new model.
Note: This is the first time i am making an issue, so please let me know if something is missing.
Example
// Models
// Controller
Acceptance criteria
The text was updated successfully, but these errors were encountered: