-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
WARNING: relational database doesn't support {strict: false} mode. {strict: true} mode will be set for model instead. #4565
Comments
I don't think it actual does anything for non-relational dbs. Does anything change when you don't set See: loopbackio/loopback-datasource-juggler#1817 @agnes512 Is this correct? |
Yes. Because |
Please remove |
@dougal83 then I am not able to add extra properties. |
And the question is why I didn't get any warnings in the previous version?🤔 Even though I was using |
The warning was added lately. We didn't change anything but add the warning. |
What about this? |
@UsmanJavedAttari if I understand your use case correctly, your model contains well-defined property (via Is my description correct? Where are you adding the extra properties to the response, is it in your controller method? My recommendation is to convert your model to a plain data object first, and then add the extra properties. class MyController {
@get(/*...*/)
async find(
@param.query.object('filter', getFilterSchemaFor(TodoList))
filter?: Filter<TodoList>,
): Promise<TodoList[]> {
const result = this.todoListRepository.find(filter);
return result.map(it => {
const data = it.toJSON();
// add your extra properties here
return data;
});
}
} There is a catch though: the OpenAPI spec will not describe the additional properties. I believe your original implementation has this problem too. A better solution is to create a new model class for your response data and explicitly describe the properties you are adding on top of the persisted data. @model()
class CustomerResponse extends Customer {
// all Product properties are inherited
// let's add some extra data now
@property()
fullName: string;
// we can fill extra properties in the constructor (for example)
constructor(data: Partial<Customer>) {
super(data);
this.fullName = this.firstName + ' ' + this.lastName;
}
}
class CustomerController {
@get(
// use schema: getModelSchemaRef(CustomerResponse, {includeRelations: true})
)
async find(
// important! the filter object does not accept "extra" properties,
// create the filter schema using the base model class
@param.query.object('filter', getFilterSchemaFor(Customer))
filter?: Filter<Customer>,
): Promise<CustomerResponse[]> {
const result = this.customerRepository.find(filter);
return result.map(it => new CustomerResponse(it));
}
} |
@UsmanJavedAttari It is possible to extend a model in the controller as follows: @model()
export class CustomUserResponse extends User {
@property({
type: 'string',
required: true,
})
extendedProp: string;
} And make the required changes: @post('/users', {
responses: {
'200': {
description: 'User',
content: {
'application/json': {
schema: {
'x-ts-type': CustomUserResponse,
},
},
},
},
},
})
async create(
// ...
): Promise<CustomUserResponse> {
// ...
const savedUser = await this.userRepository.create() // ...
// ...
return Object.assign({ extendedProp: 'example' }, savedUser);
} Lol. Just beaten. :) |
Closing as solved, and due to inactivity. |
I saw the same warning when I generated my models using LB4 CLI for PostgreSQL.
Both of us (@UsmanJavedAttari) use RDBMS not NoSQL!
Because I use RDBMS connector I expect from LB4 CLI generating a model without |
It's considered a non-issue as RDBMS connectors will ignore it and there's no material problems caused. The warning was added as a heads up to developers that the setting will be ignored. This was to prevent developers from wasting time debugging why the setting has no effect. It's not a critical error, it's purely informational and the original behaviour before the warning was added was not changed.
I'm guessing this is with regard to It's intended for workflows where Since
You don't need to remove it. It will be safely ignored by the RDBMS and function identically as if the setting was never there. |
Steps to reproduce
Use
{strict: false}
in@model(settings : {})
property.Current Behavior
Getting
Expected Behavior
The warning should not be here. As I updated the loopback cli and with that I updated loopback dependencies, after updating everything, I am getting this warning. It working fine in previous version. Using MySQL. Also getting these warnings if I get request on any URL.
Additional information
+-- @loopback/[email protected]
+-- @loopback/[email protected]
+-- @loopback/[email protected]
+-- @loopback/[email protected]
+-- @loopback/[email protected]
+-- @loopback/[email protected]
+-- @loopback/[email protected]
+-- @loopback/[email protected]
+-- @loopback/[email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
The text was updated successfully, but these errors were encountered: