How to save hasOne relationship

i tried association table users and table profiles with hasone ,
and idont know how to insert or saving data , value id form table users same with value user_id form table profiles… :frowning:

Check if you can retrieve data with associations. If you can, try edit them and save with simply $this->yourModel->save($entity)

1 Like

thank you jarekgol , its my case , descriptions ,
“thank, so i tried Association hasone on cakephp 3.4 , i dont know , but i cannot displayed data and cannot automatically update user_id , on my profiles table , …
this my code and conditions my table,”
i want association my users table and my profiles table.
this line my userstable.php
gambar
and my profilestable.php
gambar
UntitledUntitled0Untitled3Untitled1Untitled9Untitled5
Untitled55
Untitled11
Untitled88

the is no user_id column in your profile table.

you set your hasOne foreignKey to no_hp column, which is no_hp is varchar column.

so you need to change it to something like this :

in your UsersTable.php

$this->hasOne(‘Profiles’)->setName(‘Profiles’)->setForeignKey(‘user_id’)

and add user_id column to your profiles table

refer here for more details :
https://book.cakephp.org/3.0/en/orm/associations.html#hasone-associations

1 Like

Boommmmm, I got itssssssssss, hahahaha , I amm vey happy , thank all … Just Change $datakartu->Profiles->nama to $datakartu->profile->nama ;
gambar
gambar
gambar

before I apologize about the title of my post, for the user_id column automatically value I do not worry because it can give its value manually and i changed foreign key from user_id to no_hp … sorry all…

Hi wakikuk. Can you share the sourcecode?