![]() |
Hi. There is an error when converting DataСaster types for an Entity, the set() method is not specified. Because of this, type casting does not work.
Look at this https://github.com/codeigniter4/CodeIgni...st.php#L24 My code Entity: PHP Code: // Step 1, fill properties But some Casts (IntegerCast, FloatCast, ...) don't have a set (only get) method and everything breaks
You can't use DataCaster\Cast classes with Entity Property casting.
It is a misuse. You must use Entity\Cast classes. DataCaster\Cast classes are for Model Field casting. https://codeigniter4.github.io/CodeIgnit...ld-casting
This happens in the Model. I get the data in the form of an entity.
PHP Code: final class SettingsParameter extends Entity For getId() I can't get ?int So I need to move the $cast parameter to the Model? Can this affect the entity in the future?
The SettingsParameter entity does not work, because you added private properties.
Remove all the private properties if you want to use Entity.
Everything is working well. I change $attributes myself and use setXXX() to set the properties. The only problem is with typing. Before that, everything worked because there were no strict_types=1 in the system files.
I tried to put $casts into the Model and it works
Entity Property casting and Using Model Field casting with Entity behaves differently.
See Important note in https://codeigniter4.github.io/CodeIgnit...ld-casting
Hi guys,
I might have a pretty similar problem, hence I decided to hijack this thread. Disclaimer right upfront: I am talking about proprietary company code, so I need to pay attention to not leak to much information. I will still try to provide as much info as possible. Let's say I have Cart Entity and I have a Quote Entity, and I want to iterate all of the Quotes inside a Cart to see which one is active. So I foreach through the Quotes in the Cart, and on every one of them call PHP Code: $quote->__get('is_current') The call to __get calls into the system/Entity/Entity magic method, which then calls PHP Code: $this->castAs(...) PHP Code: $this->dataCaster This is where the rock hits the bird and the application dies due to $this->dataCaster being uninitialized - what I cannot understand given that this should have been initialized in the constructor of Entity. Any clue what I might be doing wrong? |
Welcome Guest, Not a member yet? Register Sign In |