# |
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 |
# |
Apr 23rd 2021, 17:04 |
admad |
@tyler.adam.lazenby Association names need to be unique |
# |
Apr 23rd 2021, 17:04 |
kevin.pfeifer |
you file as a lower `c` for Client |
# |
Apr 23rd 2021, 17:03 |
admad |
you have casing issue in your filename |
# |
Apr 23rd 2021, 17:03 |
blackjccl |
@admad Yes |
# |
Apr 23rd 2021, 17:01 |
admad |
@blackjccl and you have `class ClickMeetingRestClient {..}` in the file? |
# |
Apr 23rd 2021, 16:59 |
slackebot |
'joinType' => 'INNER', ]); $this->hasMany('Users', [ 'foreignKey' => 'account_id' ]); $this->hasMany('Addresses', [ 'foreignKey' => 'account_id', ]); }``` |
# |
Apr 23rd 2021, 16:59 |
tyler.adam.lazenby |
Here is my source ```/** * Initialize method * * @param array $config The configuration for the Table. * @return void */ public function initialize(array $config): void { parent::initialize($config); $this->setTable('accounts'); $this->setDisplayField('name'); $this->setPrimaryKey('id'); $this->addBehavior('Timestamp'); $this->belongsTo('Users', [ 'foreignKey' => 'user_id', |
# |
Apr 23rd 2021, 16:59 |
blackjccl |
Hi I am using cakephp 4 and I have created a Custom class and added a folder with my class inside the src `src/ClickMeeting/ClickMeetingRestclient.php` and in my code it is like this `namespace App\ClickMeeting;` and in I am using it like this in my component `use App\ClickMeeting\ClickMeetingRestClient;` but when I run it on my server I get this error `Class 'App\ClickMeeting\ClickMeetingRestClient' not found` |