# |
Jan 6th 2020, 20:21 |
thisimpetus |
No, just the associations; I'm creating a Publication_Author record, though, or at least trying to |
# |
Jan 6th 2020, 20:21 |
thisimpetus |
well I don't really understand that quesiton, lol, but that tells me what I need to read and what's changed since cake 2.x whatever. Thanks, pardon my nubness, front-end guy doing double-detail here. |
# |
Jan 6th 2020, 20:21 |
challgren |
Are you creating the author the same time as the Publication? |
# |
Jan 6th 2020, 20:20 |
challgren |
Whats it look like after you patch the entity and before you save it? |
# |
Jan 6th 2020, 20:19 |
thisimpetus |
cleaned up: `<input type='hidden' name='Publications.Authors.id value=8>`; a call to `debug($this->request->getData()` reveals that this is adding one entry to the data array, `Publications_Authors_id` instead of the nested array I'd expected |
# |
Jan 6th 2020, 20:18 |
thisimpetus |
(pardon the syntax gore) |
# |
Jan 6th 2020, 20:18 |
thisimpetus |
like, say this: `<input type='hidden' name='Publications.Authors.id` value=8>`; a call to `debug($this->request->getData()` reveals that this is adding one entry to the data array, `Publications_Authors_id` instead of the nested array I'd expected |
# |
Jan 6th 2020, 20:16 |
thisimpetus |
I've been reading that for a while now, I understand what the array in the Request object should look like, I don't understand what the actual html syntax cake expects should be |
# |
Jan 6th 2020, 20:15 |
challgren |
https://book.cakephp.org/3/en/orm/saving-data.html#saving-associations |
# |
Jan 6th 2020, 20:14 |
thisimpetus |
Well, the Publications_Authors table has 4 fields; id, publication_id, author_id, ordinance. What I'm trying to understand is how to create those entities from a form. With just author_id—which is how cake builds the form out of the gate—I don't get to populate that additional field. |
# |
Jan 6th 2020, 20:12 |
challgren |
why not just use author_id instead? |
# |
Jan 6th 2020, 20:12 |
thisimpetus |
no joy, hunh? : / Can I clarify my question somehow, if anyone's reading? |
# |
Jan 6th 2020, 19:53 |
thisimpetus |
(and apologies if what I'm asking is terribly unclear!) |
# |
Jan 6th 2020, 19:52 |
thisimpetus |
hasMany association has an extra field (ordinance)? |
# |
Jan 6th 2020, 19:52 |
thisimpetus |
I'm planning to just generate the form inputs for each selected Author dynamically, but I'm not sure what that should look like in order for Cake to properly create the record on the back end. I know it used to be something like giving a `name` attribute to the field akin to `[Publications][Authors][id]`. How should I create records where the |
# |
Jan 6th 2020, 19:50 |
thisimpetus |
'ordinance' field for Authors (and this is reflected in the Authors model). Here's where I'm stuck: |
# |
Jan 6th 2020, 19:50 |
thisimpetus |
Hey cake gurus. I've built a more involved UI for creating records for models with a hasMany association (here, Publication hasMany Authors). So where Cake bakes something like ` $this->Form->control( 'authors._ids', ['options' => $authors)`, I've built a javascript UI that's a little more graphical, and, importantly, also allows adding an |
# |
Jan 6th 2020, 18:41 |
ashesh.social |
I’m getting error when following the documentation |
# |
Jan 6th 2020, 18:40 |
ashesh.social |
I’m getting when following the documentation |
# |
Jan 6th 2020, 18:40 |
ashesh.social |
How to run shell scripts in cakephp 4 ?? |
# |
Jan 6th 2020, 17:36 |
ckjksl |
Alternatively, I've also tried saving it as associated data: ```$asset->tags = $assettags; $this->Assets->save($asset);``` But the duplication still happens, like the saveStrategy isn't being applied at all. |
# |
Jan 6th 2020, 17:33 |
ckjksl |
Then I link them: ```$assetsTable = TableRegistry::getTableLocator()->get('Assets'); $assetsTable->tags->link($asset, $assettags);``` According to the saveStrategy=>replace, I should be replacing its related tags completely. But what happens is that I click on that postlink three times, and I'll end up with those tag associations three times, to a total of 9. |
# |
Jan 6th 2020, 17:31 |
ckjksl |
Then for each of that tags array, I retrieve the tag and put it in an array: ```$tagEntity = $this->tags->find()->where(['title'=>$tag])->first(); $assettags[] = $tagEntity;``` |
# |
Jan 6th 2020, 17:28 |
slackebot |
array('id'=>"1", 'tags'=>['sleepy', 'smelly', 'happy']) ) );``` All that should do is update the tags for `asset` id 1 with 3 tags. |
# |
Jan 6th 2020, 17:28 |
ckjksl |
I think the relations are okay, because they're associating and saving okay, and I can retrieve the results. The problem happens when I try to add more tags. in my `test.ctp`, I have the following POST link: ```echo $this->Form->postLink( 'Update Tags (asset_id 1, \'sleepy\', \'smelly\', \'happy\' )', array('controller' => 'Assets','action' => 'updateTags'), array( 'confirm' => 'Are you sure?', 'data' => |
# |
Jan 6th 2020, 17:25 |
ckjksl |
so in the model, `AssetsTable` has: ```$this->belongsToMany('Tags', [ 'joinTable' => 'AssetTags', 'saveStrategy'=>'replace' ]);``` `TagsTable` has: ```$this->belongsToMany('Assets', [ 'joinTable' => 'AssetTags', 'saveStrategy'=>'replace' ]);``` `AssetTagsTable` has: ```$this->belongsTo('Assets', [ 'foreignKey' => 'asset_id', ]); $this->belongsTo('Tags', [ 'foreignKey' => 'tag_id', ]);``` |
# |
Jan 6th 2020, 17:22 |
ckjksl |
I'm having a bit of trouble with a simple "toxi" tag solution. This is where there are three tables, `assets`, `tags`, and `assettags`, which contains `asset_id` and `tag_id` as a lookup. I've tried a couple of ways, but the part that's failing for me is `'saveStrategy' => 'replace'` |
# |
Jan 6th 2020, 16:43 |
ricksaccous |
but that would be too hard to explain to you, heh |
# |
Jan 6th 2020, 16:43 |
ricksaccous |
you can also do an inner join and then directly search on the field |
# |
Jan 6th 2020, 16:42 |
ricksaccous |
if you want them in the match then just do something similar but do $this->Matches->find()->where(['Matches.id' => $id])->contain(['SeasonPlayers' => function ($q) |
# |
Jan 6th 2020, 16:42 |
ricksaccous |
$seasonPlayerEntities = $this->Matches->SeasonPlayers->find(['SeasonPlayers.club_id' => $matchEntity->field_name])->toArray(); |
# |
Jan 6th 2020, 16:40 |
gianmarxgagliardi |
I would like to compare the underlined fields in order to take only the players who are associated with a certain id and not all the players |
# |
Jan 6th 2020, 16:40 |
ricksaccous |
whatever you can just do this $matchEntity = $this->Matches->get($id); |
# |
Jan 6th 2020, 16:39 |
ricksaccous |
just id? |
# |
Jan 6th 2020, 16:39 |
ricksaccous |
of Matches |
# |
Jan 6th 2020, 16:39 |
ricksaccous |
what is the primary key |
# |
Jan 6th 2020, 16:39 |
slackebot |
<gianmarxgagliardi> |
# |
Jan 6th 2020, 16:38 |
ricksaccous |
it's related to the Matches.home_id ? |
# |
Jan 6th 2020, 16:38 |
ricksaccous |
but it isn't related to id huh |
# |
Jan 6th 2020, 16:38 |
ricksaccous |
ohhh |
# |
Jan 6th 2020, 16:37 |
ricksaccous |
$matchEntity = $this->Matches->find()->matching('SeasonsPlayers', function ($query) use ($id) { return $query->where(['SeasonsPlayers.club_id' => $id]); })->contain(['Foo','Bar']); |