I have a model that I am trying to populate using populate model.
public void function save(){
var rc = event.getCollection();
rc.product = populateModel( model=productService.get(rc.productid),exclude=“category” );
}
The problem is I have a ton of fields that can be left null if need be like
publishedprice
cost
reducedprice
qty
etc…
If any of these fields are are left blank than I am getting errors. We allow these fields to be null in the database so I don’t want to param these values. Here is the error I am getting, can I not use populate if I have fields that meet these requirements?
this populates the model from any matching variables in the request collection right? Well published price is an empty string which causes this error. If I were to default it to 0 than it works fine but I don’t want that because I want to keep nulls in the database.
I think it may be because your setter in Product is expecting a
datatype of date and a blank string is a string. Do you get the same
error if you populate using the setters manually?
It is expecting a numeric value and getting a string. I guess I should look at the code for populate model but I would think if there is no value you shouldnt run the setter.
ColdBox can't know if you want a blank string or a null, they aren't
the same thing. I guess you could use an interceptor to remove any
keys from the rc collection that have an empty string, that way
ColdBox won't set the vale, however that would be an issue if you want
to set a value to null that previously had a value.
Have you found a solution for this. I know I need to implement
something like (JavaCast("null", '')). I'm just not sure where to do
it. Have you check this out: