# |
Feb 18th 2020, 11:00 |
conehead |
@lilhermit Although this here says otherwise: https://book.cakephp.org/3/en/orm/saving-data.html#saving-belongsto-associations |
# |
Feb 18th 2020, 10:59 |
kaliel |
@challgren https://gist.github.com/kaliel86/d404aecebccadbee9ba84674081bdc12 |
# |
Feb 18th 2020, 10:58 |
conehead |
When using multiple entities you can set the model directly. I think you cannot do it with a "single entity" like belongsTo |
# |
Feb 18th 2020, 10:57 |
conehead |
So "`awarding_user_id` with `$awarding_user->id` " should be the way to go |
# |
Feb 18th 2020, 10:57 |
lilhermit |
@conehead was that in reply to me? Because I'm sure i've done it before |
# |
Feb 18th 2020, 10:56 |
conehead |
Think I had this discussion here already that I thought it is not that convinient :P Was told that it is convinient that way and you have to do it that way |
# |
Feb 18th 2020, 10:54 |
lilhermit |
It works if I assign `awarding_user_id` with `$awarding_user->id` |
# |
Feb 18th 2020, 10:52 |
lilhermit |
This is my `belongsTo` ``` $this->belongsTo('AwardingUsers', [ 'className' => 'Users' ]) ->setForeignKey('awarding_user_id') ->setProperty('awarding_user') ->setJoinType('INNER');``` |
# |
Feb 18th 2020, 10:50 |
slackebot |
], '[dirty]' => [ 'points' => true, 'reason' => true, 'awarding_user' => true ], '[original]' => [], '[virtual]' => [], '[hasErrors]' => false, '[errors]' => [], '[invalid]' => [], '[repository]' => 'Points' }``` |
# |
Feb 18th 2020, 10:50 |
slackebot |
=> 33, 'reason' => 'because', 'awarding_user' => $awarding_user ]); ``` The resulting entity is ```object(App\Model\Entity\Point) { 'points' => (int) 33, 'reason' => 'because', 'awarding_user' => null, '[new]' => true, '[accessible]' => [ 'points' => true, 'reason' => true, 'awarding_user_id' => true, 'created_at' => true, 'updated_at' => true, 'awarding_user' => true |
# |
Feb 18th 2020, 10:50 |
lilhermit |
Hi I have a `PointsTable` which is belongsTo `Users` (twice) the points tables as an awarding_user_id field and if I insert manually into the table and find with contains it pulls in the awarding_user. However when I create a newEntity with User assigned to `awarding_user` property it doesn't nest the `awarding_user` nor set the `awarding_user_id` ``` $points = $this->Points->newEntity([ 'points' |
# |
Feb 18th 2020, 10:45 |
martin |
`Cake\Utility\Hash::*sort*` does not understand sorting on datetime? I do `Hash::sort($users, '{n}.orders.{n}.created', 'asc');` but it is in a strange order :P |
# |
Feb 18th 2020, 10:26 |
ndm |
Should be pretty easy, just query the recommendations on `recommendationgroup_id` (or whatever you've named the foreign key) with the selected IDs from the frontend |
# |
Feb 18th 2020, 10:18 |
FunkadelicRelic |
Obvs just recommendation 1 and 2 but at least I know it is now working! Just need to figure out getting the array of ID's now instead of hard coding. |
# |
Feb 18th 2020, 10:18 |
FunkadelicRelic |
} |
# |
Feb 18th 2020, 10:18 |
FunkadelicRelic |
$data['recommendations']['_ids'] = [1,2]; |
# |
Feb 18th 2020, 10:18 |
FunkadelicRelic |
{ |
# |
Feb 18th 2020, 10:18 |
FunkadelicRelic |
public function beforeMarshal(\Cake\Event\Event $event, \ArrayObject $data, \ArrayObject $options) |
# |
Feb 18th 2020, 10:18 |
FunkadelicRelic |
Thanks @ndm - this works: |
# |
Feb 18th 2020, 10:14 |
challgren |
Thanks! I haven't gotten around to implementing my work around but yours would be good to see to see if I'm headed down the right path |
# |
Feb 18th 2020, 10:13 |
kaliel |
sure |
# |
Feb 18th 2020, 10:13 |
challgren |
@kaliel can you share your code when your done |
# |
Feb 18th 2020, 10:11 |
kaliel |
@challgren @jotpe thanks a lot forpointing me the good direction, got it working. Now i need to add a flash message when redirected :) |
# |
Feb 18th 2020, 10:06 |
Tropix |
now |
# |
Feb 18th 2020, 10:06 |
Tropix |
i'll try it nox |
# |
Feb 18th 2020, 10:05 |
neon1024 |
@Tropix https://book.cakephp.org/3/en/installation.html#permissions |
# |
Feb 18th 2020, 10:05 |
Tropix |
is not writable [CORE/src/Cache/Engine/FileEngine.php, line 412] |
# |
Feb 18th 2020, 10:05 |
Tropix |
error /var/www/html/cakeP/tmp/cache/persistent/ is not writable [CORE/src/Cache/Engine/FileEngine.php, line 412] |
# |
Feb 18th 2020, 10:04 |
Tropix |
i'm working on linux |
# |
Feb 18th 2020, 10:03 |
FunkadelicRelic |
@ndm - Thanks again - I'm going to check that out - brb. |
# |
Feb 18th 2020, 10:03 |
Tropix |
pleas can sameone help me to fix this problem |
# |
Feb 18th 2020, 10:03 |
ndm |
Like ```public function beforeMarshal(\Cake\Event\Event $event, \ArrayObject $data, \ArrayObject $options) { // ... $data['recommendations']['_ids'] = $arrayOfRecommedationPrimaryKeys; }``` https://pastebin.com/1TWSExQP |
# |
Feb 18th 2020, 10:03 |
Tropix |
Hi |
# |
Feb 18th 2020, 10:00 |
ndm |
I didn't mean to say that you should _save_ the data in `beforeMarshal`, just that you should modify it there, so that in your controller you'll receive the proper data required for saving your associations! |
# |
Feb 18th 2020, 09:59 |
FunkadelicRelic |
The assessment saves OK, but no related recommendations. |
# |
Feb 18th 2020, 09:58 |
FunkadelicRelic |
For simplicity I'm just getting the first reccomendation with ID 1 until I understand what's going on - then the idea is I will get all the recommendations based on something in the add form the user has selected. |
# |
Feb 18th 2020, 09:58 |
FunkadelicRelic |
$data->recommendations = $recs; |
# |
Feb 18th 2020, 09:58 |
FunkadelicRelic |
} |
# |
Feb 18th 2020, 09:58 |
FunkadelicRelic |
$recs = TableRegistry::getTableLocator()->get('Recommendations')->get(1); |
# |
Feb 18th 2020, 09:58 |
FunkadelicRelic |
{ |
# |
Feb 18th 2020, 09:58 |
FunkadelicRelic |
public function beforeMarshal(\Cake\Event\Event $event, \ArrayObject $data, \ArrayObject $options) |