Log message #4201841

# At Username Text
# Sep 5th 2019, 14:12 g.catania thanks anyway
# Sep 5th 2019, 14:12 g.catania ok solved. My bad! I was using the very same key "capabilities-".$this->request->getSession()->read('Auth.User.id') in two different queries holding different things. I messed up :)
# Sep 5th 2019, 14:12 david098 I added my question to stack overflow, so any help is welcome : https://stackoverflow.com/questions/57807225
# Sep 5th 2019, 14:05 maymeow updated :)
# Sep 5th 2019, 14:04 spriz I'd follow official docs ;P https://book.cakephp.org/3.0/en/orm/table-objects.html#customizing-the-entity-class-a-table-uses
# Sep 5th 2019, 14:04 maymeow when i want to change entity class i can use `protected $_entityClass = ApplicationUser::class;` ??
# Sep 5th 2019, 14:03 slackebot public function validationDefault(Validator $validator) { parent::validationDefault($validator); // TODO: Change the autogenerated stub return $validator; } } ```
# Sep 5th 2019, 14:03 maymeow its cake php ok when i extending table and entity classes? ``` class ApplicationUsersTable extends UsersTable { protected $_entityClass = ApplicationUser::class; public function initialize(array $config) { parent::initialize($config); // TODO: Change the autogenerated stub $this->hasMany('Addresses', [ 'foreignKey' => 'user_id', 'className' => 'PostBox.Addresses' ]); }
# Sep 5th 2019, 13:53 ricksaccous also you might want to clear the cache
# Sep 5th 2019, 13:53 ricksaccous what do you get?
# Sep 5th 2019, 13:52 ricksaccous if you debug after calling toArray()
# Sep 5th 2019, 13:51 g.catania nothing changed
# Sep 5th 2019, 13:51 g.catania I tried already both toArray() and execute()
# Sep 5th 2019, 13:50 ricksaccous lol
# Sep 5th 2019, 13:50 ricksaccous as for why cache even affects that I dunno
# Sep 5th 2019, 13:49 ricksaccous toArray executes the query
# Sep 5th 2019, 13:49 ricksaccous I suppose the query hasn't been executed yet, I think you're not getting a ResultSet object back when you cache, but without cache you are getting one
# Sep 5th 2019, 13:48 ricksaccous ->cache('something')->toArray();
# Sep 5th 2019, 13:48 ricksaccous try adding toArray after cache
# Sep 5th 2019, 13:47 g.catania if I omit the ->cache() part works
# Sep 5th 2019, 13:46 g.catania foreach ($user_capabilities as ....) <- this throws the error reported above
# Sep 5th 2019, 13:46 g.catania $user_capabilities = $this->Capabilities->find() ->contain('CapabilityGroups') ->matching('Groups.Users', function($q) { return $q->where(['Users.id' => $this->request->getSession()->read('Auth.User.id')]); })->cache("capabilities-".$this->request->getSession()->read('Auth.User.id'), 'capabilities');
# Sep 5th 2019, 13:42 g.catania I'm running on CakePHP 3.0.x
# Sep 5th 2019, 13:42 ricksaccous @g.catania show code
# Sep 5th 2019, 13:41 g.catania As matter of fact, my foreach (working flawlessy before cache() introduction) throws: "Objects returned by Cake\ORM\Query::getIterator() must be traversable or implement interface Iterator"
# Sep 5th 2019, 13:40 g.catania Hi guys. I'm having an hard time figuring out why chaining ->cache() to my query, I can't iterate it. From docs I read "->cache() returns this, meaning a Cake\ORM\Query object".
# Sep 5th 2019, 13:39 david098 @colas.ruamps that isn't working either as clients are put multiple times in the resultset for every statement due... ->group(['Clients.id']) is also no solution as only 1 statement is left over in the resultset
# Sep 5th 2019, 13:34 alexdd55976 ok, see your point.
# Sep 5th 2019, 13:34 david098 @alexdd55976 I prefer to start from clients as i want to loop through the clients and send them an email with the request of missing statements for their contracts
# Sep 5th 2019, 13:27 colas.ruamps @david098 you could try to add `->matching('Contracts.Statements', function(....`
# Sep 5th 2019, 13:26 alexdd55976 @david098 this is my rough idea ``` $query = $this->Contracts->where(['Contracts.published'=>true]); }) ->contain('Contracts.Statements', function ($q) use ($date) { return $q ->where(['amount IS'=>NULL]) ->where(['Statements.periodend <=' => '2019-09-30']) ->order(['periodend'=>'ASC']); }) ->contain('Clients') ->order(['Clients.name'=>'ASC']); ```
# Sep 5th 2019, 13:25 neon1024 Is there a funky collection method which I could use to pick the highest value in an array of arrays?
# Sep 5th 2019, 13:23 david098 This my query at the moment, but it is returning all clients including contracts with no statements due
# Sep 5th 2019, 13:23 alexdd55976 the biggest factor seems to be contracts, so start here.. get all contracts.published, then get the statements and the clients
# Sep 5th 2019, 13:22 david098 `$query = $this->Statements->Contracts->Clients->find();` `$query` ` ->matching('Contracts', function ($q) {` ` return $q->where(['Contracts.published'=>true]);` ` })` ` ->contain('Contracts.Statements', function ($q) use ($date) {` ` return $q` ` ->where(['amount IS'=>NULL])` ` ->where(['Statements.periodend <=' => $date])` ` ->order(['periodend'=>'ASC']);` ` })` ` ->order(['Clients.name'=>'ASC']);`
# Sep 5th 2019, 13:21 alexdd55976 you could try (the obvious) to get over clients to contracts to statements.
# Sep 5th 2019, 13:21 alexdd55976 depenends from which side you comin.
# Sep 5th 2019, 13:15 slackebot will I end up doing loops and do "manual"checks?
# Sep 5th 2019, 13:15 david098 I got a querybuilder issue, I have clients who have many to many contracts what have many to many statements. I want to get all Clients with their active contracts (Contracts.published = 1) where there are statements due (Statements.periodend <= 2019-09-30). So if there is not an active contract or if there are no statements due under the contract i don't want to get the client in the resultset. Is this possible in 1 query(builder) or
# Sep 5th 2019, 13:04 leonardo.crecente actually print_r('Index'); exit;
# Sep 5th 2019, 13:03 leonardo.crecente in /httpdocs/blog/index.php I,ve put a print_r(); exit; to see if request gets there...