# |
Apr 23rd 2021, 17:38 |
tyler.adam.lazenby |
its nice |
# |
Apr 23rd 2021, 17:38 |
kevin.pfeifer |
but i will have to take a look at that lazyload trait, it seems pretty cool :thinking_face: |
# |
Apr 23rd 2021, 17:36 |
kevin.pfeifer |
the "default", as little code as possible, cakephp way is just preconfigured with quite easy to understand defaults |
# |
Apr 23rd 2021, 17:36 |
tyler.adam.lazenby |
Yup, thanks for your help |
# |
Apr 23rd 2021, 17:35 |
kevin.pfeifer |
you can basically create any assiciation as you like |
# |
Apr 23rd 2021, 17:35 |
kevin.pfeifer |
so as you see |
# |
Apr 23rd 2021, 17:35 |
kevin.pfeifer |
:) |
# |
Apr 23rd 2021, 17:35 |
tyler.adam.lazenby |
That .... actually makes sense |
# |
Apr 23rd 2021, 17:34 |
kevin.pfeifer |
since you used `'propertyName' => 'User',` |
# |
Apr 23rd 2021, 17:34 |
tyler.adam.lazenby |
smh its always something stupidly simple like that |
# |
Apr 23rd 2021, 17:33 |
kevin.pfeifer |
could it be that its actually `$account->User` ? |
# |
Apr 23rd 2021, 17:32 |
slackebot |
LIMIT 1``` |
# |
Apr 23rd 2021, 17:32 |
slackebot |
User__last_name, User.phone AS User__phone, User.email AS User__email, User.login AS User__login, User.password AS User__password, User.created AS User__created, User.updated AS User__updated, User.company_name AS User__company_name, User.token AS User__token, User.account_id AS User__account_id FROM accounts Accounts INNER JOIN users User ON User.id = (Accounts.user_id) WHERE Accounts.id = 15 |
# |
Apr 23rd 2021, 17:32 |
tyler.adam.lazenby |
```SELECT Accounts.id AS Accounts__id, Accounts.user_id AS Accounts__user_id, Accounts.name AS Accounts__name, Accounts.logo AS Accounts__logo, Accounts.created AS Accounts__created, Accounts.modified AS Accounts__modified, Accounts.phone AS Accounts__phone, User.id AS User__id, User.user_type_id AS User__user_type_id, User.first_name AS User__first_name, User.last_name AS |
# |
Apr 23rd 2021, 17:30 |
tyler.adam.lazenby |
let me get rid of the dd and I will check |
# |
Apr 23rd 2021, 17:30 |
kevin.pfeifer |
or is there something wrong with the join |
# |
Apr 23rd 2021, 17:30 |
kevin.pfeifer |
sql looks right in debug kit? |
# |
Apr 23rd 2021, 17:29 |
tyler.adam.lazenby |
but just for kicks and giggles I just tried it, same result |
# |
Apr 23rd 2021, 17:29 |
kevin.pfeifer |
ok i have no experience with that ,:) |
# |
Apr 23rd 2021, 17:28 |
tyler.adam.lazenby |
I am not using the contain command because I am using the lazyloadtrait |
# |
Apr 23rd 2021, 17:28 |
kevin.pfeifer |
in your query |
# |
Apr 23rd 2021, 17:28 |
kevin.pfeifer |
do you contain `User` as well now? |
# |
Apr 23rd 2021, 17:27 |
tyler.adam.lazenby |
I have made sure to have the lazyloadingtrait being used by my account entity, but when I call $account->user.... it returns null |
# |
Apr 23rd 2021, 17:26 |
tyler.adam.lazenby |
hmmm |
# |
Apr 23rd 2021, 17:26 |
kevin.pfeifer |
one `User` and one `Users` yes |
# |
Apr 23rd 2021, 17:25 |
tyler.adam.lazenby |
So this isn't going to create two properties (users and user)? ```$this->belongsTo('User', [ 'foreignKey' => 'user_id', 'joinType' => 'INNER', 'className' => 'Users', 'bindingKey' => 'id', 'propertyName' => 'User', ]); $this->hasMany('Users', [ 'foreignKey' => 'account_id' ]);``` |
# |
Apr 23rd 2021, 17:24 |
kevin.pfeifer |
but you can basically set the first parameter (for me `ParentProjects` and `ChildProjects` ) as whatever you like |
# |
Apr 23rd 2021, 17:24 |
blackjccl |
Thank you that was the mistake @kevin.pfeifer @admad |
# |
Apr 23rd 2021, 17:24 |
kevin.pfeifer |
depending on your associations you need to set the right parameters described in https://book.cakephp.org/4/en/orm/associations.html |
# |
Apr 23rd 2021, 17:23 |
slackebot |
projects i call `$project = $this->Projects->get( $id, [ 'contain' => ['Childcts'] ]);` |
# |
Apr 23rd 2021, 17:23 |
slackebot |
'joinTable' => 'projects_projects', 'foreignKey' => 'parent_id', 'targetForeignKey' => 'child_id' ] );``` Basically here i only have a `projects` table with an id and a separate `projects_projects` table with only the columns `parent_id` and `child_id` If i want to access the parent projects i call `$project = $this->Projects->get( $id, [ 'contain' => ['ParentProjects'] ]);` And i want to access the child |
# |
Apr 23rd 2021, 17:23 |
kevin.pfeifer |
@tyler.adam.lazenby here is an example for a Parent-Child Join for Projects with custom Identifieres ``` $this->belongsToMany( 'ParentProjects', [ 'className' => 'Projects', 'joinTable' => 'projects_projects', 'foreignKey' => 'child_id', 'targetForeignKey' => 'parent_id' ] ); $this->belongsToMany( 'ChildProjects', [ 'className' => 'Projects', |
# |
Apr 23rd 2021, 17:15 |
admad |
read the 1st section of this page and you will have your answer https://book.cakephp.org/4/en/orm/associations.html |
# |
Apr 23rd 2021, 17:13 |
tyler.adam.lazenby |
or is the association name the first property of the declaration? |
# |
Apr 23rd 2021, 17:12 |
tyler.adam.lazenby |
now I need to figure out how to give the associations unique names. I thought this would work but.... ```$this->belongsTo('Users', [ 'foreignKey' => 'user_id', 'joinType' => 'INNER', 'property' => 'account_holder' ]); $this->hasMany('Users', [ 'foreignKey' => 'account_id' ]);``` |
# |
Apr 23rd 2021, 17:08 |
tyler.adam.lazenby |
@admad oh right.... that... makes sense. I feel dumb |
# |
Apr 23rd 2021, 17:08 |
kevin.pfeifer |
@blackjccl to be more specific: Your Classname is `ClickMeetingRestClient` but your filename is `ClickMeetingRestclient.php` |
# |
Apr 23rd 2021, 17:07 |
admad |
@blackjccl geez man how much spoon feeding do you need? @kevin.pfeifer told you exactly what your mistake is |
# |
Apr 23rd 2021, 17:06 |
kevin.pfeifer |
which is the identifier for that relation |
# |
Apr 23rd 2021, 17:06 |
kevin.pfeifer |
``` $this->belongsTo('Users', [ 'foreignKey' => 'user_id', 'joinType' => 'INNER', ]); $this->hasMany('Users', [ 'foreignKey' => 'account_id' ]);``` have both `Users` as a first parameter |
# |
Apr 23rd 2021, 17:06 |
blackjccl |
@admad what do you mean i'm doing wrong |