# |
Jun 3rd 2021, 16:55 |
richard |
stupid question but how do i run bin/cake as www-data? |
# |
Jun 3rd 2021, 14:14 |
dereuromark |
For keeping them in sync I use https://www.dereuromark.de/2020/02/25/cakephp-tips-winter-2020/#keep-fixtures-in-sync-with-tables which helps a lot to find the fields someone added but didnt adjust the fixtures with. That can lead to tests being green while in reality the (required) fields can cause errors. So best to check this once in a while. |
# |
Jun 3rd 2021, 12:00 |
jamison508 |
You can certainly test both models and controllers, though you'd be testing the table classes and not the entities so much. My advice is when testing validation, write tests for successful (happy path) validation too and not just unsuccessful (sad path) validation. You should be using fixtures pretty much always IMO. These require a test connection configured in your config. The tables will be dropped and recreated/seeded |
# |
Jun 3rd 2021, 12:00 |
slackebot |
every test run. Make sure to keep these updated with your schema. |
# |
Jun 3rd 2021, 11:48 |
v.plancher |
Hello there. This is not a question about unit testing CakePHP itself, but about unit testint MVC frameworks. I'm new at unit testing, and I wonder if I should write tests on : • controllers : because this is where it "begins" and it could be a way to test models too. • models (tables/entities) : because this is where most of code is written, and because it is easier to write tests on very specific methods Do you have |
# |
Jun 3rd 2021, 11:48 |
slackebot |
advices on that? A second question. Many features rely on data from the database with many associations (like: Orders > OrderLines > Articles / Discounts > ...). It means I'd need to create many fixtures lines. When is it better to use fixtures? To use a test database? |
# |
Jun 3rd 2021, 10:24 |
kevin.pfeifer |
as ndm already mentioned with that link https://stackoverflow.com/questions/30241975/how-to-limit-contained-associations-per-record-group/30270675#30270675 |
# |
Jun 3rd 2021, 10:24 |
kevin.pfeifer |
the reason behind that question is, that mysql 5.6 doesn't allow your problem to be solved, because it is quite a difficult one |
# |
Jun 3rd 2021, 10:23 |
kevin.pfeifer |
do you use MySQL 5.6 as a database server or something different? |
# |
Jun 3rd 2021, 10:21 |
etibor |
Kevin thank you |
# |
Jun 3rd 2021, 09:41 |
kevin.pfeifer |
i would have to test that myself |
# |
Jun 3rd 2021, 09:37 |
etibor |
and probably becuase as you wrote limiting associated data is not possible right now |
# |
Jun 3rd 2021, 09:37 |
etibor |
```return $->last()``` brings: Call to undefined method App\Model\Entity\UrlFile::aliasFields() |
# |
Jun 3rd 2021, 09:36 |
kevin.pfeifer |
ok yes |
# |
Jun 3rd 2021, 09:36 |
etibor |
for sorting for example |
# |
Jun 3rd 2021, 09:36 |
kevin.pfeifer |
what you mean by you can't use it in pagination? |
# |
Jun 3rd 2021, 09:35 |
kevin.pfeifer |
limiting associated data is not possible right now |
# |
Jun 3rd 2021, 09:35 |
etibor |
could be work the virtual field but as i remember it can not used in the pagination |
# |
Jun 3rd 2021, 09:35 |
kevin.pfeifer |
but seems like ndm already answered your question as well |
# |
Jun 3rd 2021, 09:33 |
kevin.pfeifer |
but i guess thats easier now |
# |
Jun 3rd 2021, 09:33 |
kevin.pfeifer |
sure you will load in sql more then you actually show |
# |
Jun 3rd 2021, 09:32 |
kevin.pfeifer |
how about you just contain your normal UrlFiles and add a virtual field which just returns the last connected element in that array? |
# |
Jun 3rd 2021, 09:32 |
etibor |
``` $documents->contain([ 'States', 'LastUrlFile'=> function($query){ return $query->last(); }``` |
# |
Jun 3rd 2021, 09:31 |
etibor |
because last() or first does not works |
# |
Jun 3rd 2021, 09:30 |
etibor |
i added as an additional association |
# |
Jun 3rd 2021, 09:28 |
kevin.pfeifer |
i gues you "just" need the last url file for a given entity |
# |
Jun 3rd 2021, 09:28 |
kevin.pfeifer |
additionally: why do you need it as an association? |
# |
Jun 3rd 2021, 09:27 |
kevin.pfeifer |
what SQL does it generate |
# |
Jun 3rd 2021, 09:27 |
etibor |
does not works |
# |
Jun 3rd 2021, 09:27 |
etibor |
using : `$this->hasOne('LastUrlFile'` |
# |
Jun 3rd 2021, 09:26 |
kevin.pfeifer |
the first parameter is YOUR name what you want to call that association |
# |
Jun 3rd 2021, 09:26 |
etibor |
In DocumentsTable.php i have: ```$this->hasMany('UrlFiles', ['className'=>'UrlFiles', 'joinType' => 'INNER', 'dependent'=>true, 'property'=>'last_url_file' ]); $this->hasMany('LastUrlFile', ['className'=>'UrlFiles', 'joinType' => 'INNER', 'Limit'=>1, 'Sort'=>([ 'UrlFiles.id' => 'DESC', ]), 'dependent'=>true, |
# |
Jun 3rd 2021, 09:26 |
slackebot |
'property'=>'last_url_file' ]);``` |
# |
Jun 3rd 2021, 09:26 |
kevin.pfeifer |
so this doesn't work ```$this->hasMany('UrlFiles', [ 'className'=>'UrlFiles', ... $this->hasOne('UrlFiles', [ 'className'=>'LastUrlFiles', .....``` |
# |
Jun 3rd 2021, 09:25 |
kevin.pfeifer |
association names (the first parameter) need to be unique |
# |
Jun 3rd 2021, 09:25 |
etibor |
yes i try to do it with additional association |
# |
Jun 3rd 2021, 09:25 |
etibor |
but in the Documents Model i dont have url_file_id |
# |
Jun 3rd 2021, 09:25 |
kevin.pfeifer |
as already said in support channel |
# |
Jun 3rd 2021, 09:24 |
kevin.pfeifer |
i would guess it would be easier for you if you add another association |
# |
Jun 3rd 2021, 09:24 |
etibor |
in the UrlFiles Model i have the foreign key |
# |
Jun 3rd 2021, 09:24 |
kevin.pfeifer |
as for cakephp |
# |
Jun 3rd 2021, 09:24 |
kevin.pfeifer |
you need the forgein key to connect the 2 tables |
# |
Jun 3rd 2021, 09:23 |
kevin.pfeifer |
from a DB structure point a hasMany and hasOne looks the same |
# |
Jun 3rd 2021, 09:22 |
etibor |
but i feel that if i dont have the foreign_key in the Main Model it will never be accasseble as HasONe |
# |
Jun 3rd 2021, 09:21 |
etibor |
yes exactly thats the case |
# |
Jun 3rd 2021, 09:21 |
kevin.pfeifer |
which should actually be a hasONe |
# |
Jun 3rd 2021, 09:21 |
kevin.pfeifer |
so you got a hasMany |
# |
Jun 3rd 2021, 09:19 |
etibor |
is there any chance to acces like $last_url_file->url_path insted of $last_url_file[0]->url_path |
# |
Jun 3rd 2021, 09:17 |
philo.hamel |
sorry, I'm not sure |
# |
Jun 3rd 2021, 09:10 |
etibor |
i would like to get only a single record |
# |
Jun 3rd 2021, 09:10 |
etibor |
```$this->hasMany('LastUrlFile', ['className'=>'UrlFiles', 'joinType' => 'INNER', 'Limit'=>1, 'Sort'=>([ 'UrlFiles.id' => 'DESC', ]), 'dependent'=>true, 'property'=>'last_url_file' ]);``` it is working but its returns an array insted of a single record |
# |
Jun 3rd 2021, 09:09 |
etibor |
but actually originally it was an HasMany association, so i dont have a foreign_key in the main model |
# |
Jun 3rd 2021, 09:08 |
etibor |
i having issue with: would like to make another association to the same model, the first is a HasMayn while the second is a HasOne |
# |
Jun 3rd 2021, 09:07 |
etibor |
thank you really much |
# |
Jun 3rd 2021, 09:05 |
kevin.pfeifer |
sure |
# |
Jun 3rd 2021, 09:05 |
etibor |
can i ask you a quick question? |
# |
Jun 3rd 2021, 09:05 |
etibor |
hello Kevin |
# |
Jun 3rd 2021, 09:04 |
etibor |
since i dont have in the Main Model the url_file_id |
# |
Jun 3rd 2021, 09:04 |
etibor |
so back to the question, it does not contained when i use HasOne insted of HasMany |
# |
Jun 3rd 2021, 09:02 |
etibor |
moment |
# |
Jun 3rd 2021, 09:01 |
etibor |
``j |
# |
Jun 3rd 2021, 09:01 |
etibor |
`$this->hasMany('LastUrlFile', [ 'className'=>'UrlFiles', 'joinType' => 'INNER', 'Limit'=>0, 'Sort'=>([ 'UrlFiles.id' => 'DESC', ]), 'dependent'=>true, 'property'=>'last_url_file' ]);` |
# |
Jun 3rd 2021, 08:59 |
philo.hamel |
triple ` |
# |
Jun 3rd 2021, 08:58 |
etibor |
thank you @philo.hamel okey, first please tell me how can i insert a whole code block not just one line here |
# |
Jun 3rd 2021, 08:55 |
philo.hamel |
you'll need conditions to figure out which row to fetch for the association |
# |
Jun 3rd 2021, 08:54 |
slackebot |
->setProperty('work_address') ->setConditions(['WorkAddress.label' => 'Work']) ->setDependent(true); } }``` |
# |
Jun 3rd 2021, 08:54 |
philo.hamel |
```class UsersTable extends Table { public function initialize(array $config): void { $this->hasOne('HomeAddress', [ 'className' => 'Addresses' ]) ->setProperty('home_address') ->setConditions(['HomeAddress.label' => 'Home']) ->setDependent(true); $this->hasOne('WorkAddress', [ 'className' => 'Addresses' ]) |
# |
Jun 3rd 2021, 08:54 |
philo.hamel |
@etibor have you seen this example? |
# |
Jun 3rd 2021, 08:26 |
etibor |
or is this not possible without the Documents table have an last_file_id db field?? |
# |
Jun 3rd 2021, 08:23 |
etibor |
so without the [0] index i would like to get |
# |
Jun 3rd 2021, 08:22 |
etibor |
i do this becuase i would like to get the last inserted url_files record and not reach like $last_model[0]->url_path // this is the only working solution now |
# |
Jun 3rd 2021, 08:21 |
etibor |
`$this->hasMany('UrlFiles', [` `'className'=>'UrlFiles',` and `$this->hasOne('UrlFiles', [` `'className'=>'LastUrlFiles',` the LastUrlFiles Model does not load in the contain |
# |
Jun 3rd 2021, 08:20 |
etibor |
but it does not work |
# |
Jun 3rd 2021, 08:20 |
etibor |
i would like to make another association to the same model, the first is a HasMayn while the second is a HasOne |
# |
Jun 3rd 2021, 08:19 |
etibor |
hello everyone |
# |
Jun 3rd 2021, 07:07 |
paolo.bragagni |
there is a better way? |
# |
Jun 3rd 2021, 07:07 |
paolo.bragagni |
in my old template with cake2 I rewrote the beforeFind in model where I tranformed fields in Ita |
# |
Jun 3rd 2021, 07:05 |
paolo.bragagni |
How to search between date with https://github.com/FriendsOfCake/search ? and how to set date and numbers in italian (I mean dd/gg/YYYY) in search plugin? |
# |
Jun 3rd 2021, 04:57 |
y.teruyacookie |
@ndm Thank you very much! I thought it is the problem about memory overload. Simply I make a mistake about how to use finder method. I have solved this problem finally. Thank you very much!! |
# |
Jun 3rd 2021, 00:47 |
ndm |
@etibor Because limiting associations isn't supported out of the box. `hasMany` and `belongsToMany` associations are being retrieved in _one_ separate query, so if you apply a limit to it, that query will only receive one record for _all_ your `Documents`, not for _each one_ of them. Try https://github.com/icings/partitionable/, or have a look at the examples in |
# |
Jun 3rd 2021, 00:47 |
slackebot |
https://stackoverflow.com/questions/30241975/how-to-limit-contained-associations-per-record-group/30270675#30270675, for single results you can possibly hack something in using association conditions. Other than that you don't have too many options, the next best thing would then be to manually load and inject the associated results in a result formatter, either using similar partitionable windows, or god forbid, by issuing one query |
# |
Jun 3rd 2021, 00:47 |
slackebot |
for each of your `Documents` results. |
# |
Jun 2nd 2021, 22:42 |
etibor |
why i can not get only one element from the associated Model: `'PrivateThesises.PrivateThesisUrlFiles' => function($q) {` `$q` `->where(['Documents.class'=>'Types'])` `->order('UrlFiles.created ASC')` `->limit(1)` `;` `return $q;//->first() or last() does not works` `},` |
# |
Jun 2nd 2021, 22:25 |
ndm |
tumbleweed |
# |
Jun 2nd 2021, 22:05 |
etibor |
hello everyone |
# |
Jun 2nd 2021, 15:50 |
duchdamian |
thanks for your help, have a good day! |
# |
Jun 2nd 2021, 15:49 |
duchdamian |
oh I see what's up, so the --config it's pulling into rector is actually a php file and not a yaml file, the following command worked if I point it to the yaml directly. It's an issue with the upgrade tool I believe `/cake_upgrade/vendor/bin/rector process --autoload-file='/var/www/html/vendor/autoload.php' *--config='/cake_upgrade/vendor/rector/rector/config/set/cakephp/cakephp40.yaml'* --working-dir='/var/www/html/src' |
# |
Jun 2nd 2021, 15:49 |
slackebot |
'/var/www/html/src'` |
# |
Jun 2nd 2021, 15:47 |
kevin.pfeifer |
yea, i mean just skip rector |
# |
Jun 2nd 2021, 15:47 |
duchdamian |
that error comes from rector not cake and I do have all logging enabled |
# |
Jun 2nd 2021, 15:46 |
kevin.pfeifer |
@duchdamian I have heard of many times where the rector upgrade tool was pretty finicky to setup I would just perform the "pure" composer update, set the ```'Error' => [ 'errorLevel' => E_ALL, ]``` and go from one error to the next |
# |
Jun 2nd 2021, 15:44 |
duchdamian |
CakePHP upgrade tool (master) https://github.com/cakephp/upgrade CakePHP skeleton app (3.x) https://github.com/cakephp/app/tree/3.x Followed the 4.0 upgrade guide (https://book.cakephp.org/4/en/appendices/4-0-upgrade-guide.html) |
# |
Jun 2nd 2021, 15:43 |
kevin.pfeifer |
https://github.com/FriendsOfCake/awesome-cakephp#auditing--logging |
# |
Jun 2nd 2021, 15:42 |
slackebot |
Command sent from Slack by kevin.pfeifer: |
# |
Jun 2nd 2021, 15:42 |
slackebot |
~tell iquana about awesome |
# |
Jun 2nd 2021, 15:39 |
thomas078 |
need to do audit trail tool. Is there a proper plugin or just to write myself? |
# |
Jun 2nd 2021, 15:12 |
duchdamian |
Hi everyone - I'm in beginning stages of converting an app from cake 3.x to 4.x and the cake upgrade tool (rector) returns an error what sounds to me like a yaml parsing error. I'm not sure if that's a right place to post this but if someone ran into this before or knows what the issue might be I could really use some help. Also getting the exact same results against 3.9 skeleton app. CLI running PHP 7.4 ```bash-5.0# |
# |
Jun 2nd 2021, 15:12 |
slackebot |
bin/cake upgrade rector --rules cakephp40 /var/www/html/src -v Detecting autoload file for /var/www/html/src -> Checking /var/www/html/src/vendor/autoload.php -> Checking /var/www/html/vendor/autoload.php -> Found /var/www/html/vendor/autoload.php Running /cake_upgrade/vendor/bin/rector process --autoload-file='/var/www/html/vendor/autoload.php' --config='/cake_upgrade/config/rector/cakephp40.php' --working-dir='/var/www/html/src' |
# |
Jun 2nd 2021, 15:12 |
slackebot |
'/var/www/html/src' [ERROR] Mapping values are not allowed in multi-line blocks in "/cake_upgrade/config/rector/cakephp40.php" at line 1 (near "<?php"). Rector applied successfully``` |
# |
Jun 2nd 2021, 15:10 |
ndm |
https://book.cakephp.org/4/en/orm/retrieving-data-and-resultsets.html#custom-finder-methods |