Log message #4264350

# At Username Text
# May 29th 2021, 21:59 kevin.pfeifer ha ok
# May 29th 2021, 21:59 kevin.pfeifer i guess my solution above is a bit too hacky
# May 29th 2021, 21:56 kevin.pfeifer lets check the docs
# May 29th 2021, 21:55 kevin.pfeifer to check the connected entity
# May 29th 2021, 21:55 etibor yes min and max values can be change in the future
# May 29th 2021, 21:55 kevin.pfeifer i guess you would need to have the same logic on the other model as well
# May 29th 2021, 21:55 kevin.pfeifer but after e.g. 1 day these min and max values change and the connected entity is then wrong?
# May 29th 2021, 21:54 etibor if not with depending on the values of another entity
# May 29th 2021, 21:54 kevin.pfeifer I am just thinking that through What if your first “add” action works because your connected storage entity has valid min and max values
# May 29th 2021, 21:54 etibor but how would you deal with that?
# May 29th 2021, 21:53 etibor okey i found in my directory the Factory Locator
# May 29th 2021, 21:53 kevin.pfeifer depending on the values of another entitiy
# May 29th 2021, 21:53 kevin.pfeifer to have input validation present
# May 29th 2021, 21:53 kevin.pfeifer but I personally never had that case to be honest
# May 29th 2021, 21:52 kevin.pfeifer its present
# May 29th 2021, 21:52 kevin.pfeifer https://github.com/cakephp/cakephp/blob/3.x/src/Datasource/FactoryLocator.php
# May 29th 2021, 21:52 kevin.pfeifer ah wait
# May 29th 2021, 21:52 etibor i am looking for the using of FactoryLocator Class in Cake but at first sight its seem its for cake4
# May 29th 2021, 21:52 kevin.pfeifer but seems like that factory locator is also present in cake3 so it should work :) https://github.com/cakephp/cakephp/blob/master/src/Datasource/FactoryLocator.php
# May 29th 2021, 21:50 kevin.pfeifer and with that table object you can then (as like you where in the controller or in the model of that table) load entities and check their fields
# May 29th 2021, 21:49 kevin.pfeifer you can basically load any table from anywhere when you have a Table Locator Object
# May 29th 2021, 21:49 slackebot $value){ return false; // Invalid! } return true; },```
# May 29th 2021, 21:49 kevin.pfeifer ``` 'rule' => function( $value, $context ) { // Get the selected $selected_storage_id = $context['data']['storage_id']; $table_locator = FactoryLocator::get('Table'); $StorageTable = $table_locator->get('Storage'); $storage_entity = $StorageTable->get($selected_storage_id); if($storage_entity->somefield < value || $storage_entity->otherfield >
# May 29th 2021, 21:48 kevin.pfeifer but i would do something like that
# May 29th 2021, 21:48 kevin.pfeifer i don’t know if you have the FactoryLocator Class in Cake 3
# May 29th 2021, 21:46 etibor thank you Kevin
# May 29th 2021, 21:45 kevin.pfeifer yea i am currently in the process of preparing that
# May 29th 2021, 21:44 etibor "the only thing you need to do by hand in there is load the values from your other Table" - this part i dont really know how to do it
# May 29th 2021, 21:44 etibor how The main Model is dependent on the Other Model's field value
# May 29th 2021, 21:43 etibor ```function( $value, $context ) { // ... some logic return true; },``` As i good unserstand here will declarete
# May 29th 2021, 21:42 kevin.pfeifer the only thing you need to do by hand in there is load the values from your other Table
# May 29th 2021, 21:42 kevin.pfeifer and basically you can add any custom rule you want to any field
# May 29th 2021, 21:42 kevin.pfeifer this is inside my Tables ```public function validationDefault( Validator $validator ): Validator {``` function
# May 29th 2021, 21:41 kevin.pfeifer ``` $validator->boolean( 'is_done' ) ->allowEmptyString( 'is_done' ) ->add( 'is_done', 'check_is_done_fields', [ 'rule' => function( $value, $context ) { // ... some logic return true; }, 'message' => __d('alfred_projects', 'Please fill out all necessary fields to close a project' ) ] );```
# May 29th 2021, 21:40 etibor thank you Kevin, i stuck by the buildRules
# May 29th 2021, 21:38 kevin.pfeifer let me grab one of my examples
# May 29th 2021, 21:38 kevin.pfeifer well this would be perfect for a custom validation rule I would guess
# May 29th 2021, 21:38 kevin.pfeifer i see
# May 29th 2021, 21:38 kevin.pfeifer ahh
# May 29th 2021, 21:37 etibor well, the first part is right, and the second is a bit different, Documents stores the score field, and Storage stores the score minimal and maximal value(there can be different Storeges) and Document's instances have storage_id
# May 29th 2021, 21:35 kevin.pfeifer am i right?