# |
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 |
kevin.pfeifer |
but seems like ndm already answered your question as well |
# |
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: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 |
slackebot |
'property'=>'last_url_file' ]);``` |
# |
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 |
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 |