# |
Jan 7th 2020, 19:03 |
this.impetus |
*got it |
# |
Jan 7th 2020, 19:03 |
slackebot |
!!!! got |
# |
Jan 7th 2020, 19:03 |
slackebot |
Command sent from Slack by this.impetus: |
# |
Jan 7th 2020, 19:00 |
this.impetus |
Because there are literally hundreds of Authors, I'm generating the form inputs from a JS script as they're selected, rather than creating n-hundred x 4 fields that 99% of which would go unused |
# |
Jan 7th 2020, 18:59 |
this.impetus |
... god I miss photoshop.... |
# |
Jan 7th 2020, 18:59 |
this.impetus |
precisely |
# |
Jan 7th 2020, 18:59 |
this.impetus |
Yes |
# |
Jan 7th 2020, 18:59 |
ndm |
Depends on what exactly you want to achieve. Are you trying associate your grant with existing authors while providing custom join data? |
# |
Jan 7th 2020, 18:57 |
this.impetus |
By way of example, this is the request data ```'authors' => [ (int) 0 => [ '_joinData' => [ 'ordinance' => '1', 'principle_investigator' => 'false', 'starred' => '' ] ],``` How should that be different? |
# |
Jan 7th 2020, 18:57 |
this.impetus |
Yeah, ok—the validation errors are silly and my bad, already fixed. But I dont understand what the data ought to look like for creating *only* associations, and not new authors. |
# |
Jan 7th 2020, 18:56 |
ndm |
*authors... but also join data records |
# |
Jan 7th 2020, 18:56 |
ndm |
You can use for example gists instead (https://gist.github.com/) where you can paste loooong code. That being said, there's a bunch of validation errors, and that are new join data records yes, if you want to update them, you need to pass their primary key |
# |
Jan 7th 2020, 18:54 |
this.impetus |
Oh... wtf.. is this trying to create new authors? |
# |
Jan 7th 2020, 18:54 |
slackebot |
=> [ '_joinData' => true ], '[original]' => [], '[virtual]' => [], '[hasErrors]' => true, '[errors]' => [ 'first_name' => [ '_required' => 'This field is required' ], 'last_name' => [ '_required' => 'This field is required' ] ], '[invalid]' => [], '[repository]' => 'Authors' },``` |
# |
Jan 7th 2020, 18:54 |
slackebot |
true, '[errors]' => [ 'principle_investigator' => [ 'boolean' => 'The provided value is invalid' ] ], '[invalid]' => [ 'principle_investigator' => 'false' ], '[repository]' => 'GrantsAuthors' }, '[new]' => true, '[accessible]' => [ 'first_name' => true, 'middle_name' => true, 'last_name' => true, 'grants' => true, 'publications' => true, 'features' => true ], '[dirty]' |
# |
Jan 7th 2020, 18:54 |
slackebot |
object(App\Model\Entity\Author) { '_joinData' => object(App\Model\Entity\GrantsAuthor) { 'ordinance' => (int) 1, '[new]' => true, '[accessible]' => [ 'grant_id' => true, 'author_id' => true, 'principle_investigator' => true, 'ordinance' => true, 'grant' => true, 'author' => true ], '[dirty]' => [ 'ordinance' => true ], '[original]' => [], '[virtual]' => [], '[hasErrors]' => |
# |
Jan 7th 2020, 18:54 |
this.impetus |
```/src/Controller/GrantsController.php (line 60)object(App\Model\Entity\Grant) { 'cvsection_id' => (int) 3, 'cvsubsection_id' => (int) 1, 'title' => 'asdasd', 'subtitle' => 'asda ds', 'institution_id' => (int) 1, 'institution_details' => '', 'start_year' => '1951', 'end_year' => '1956', 'amount' => '1000', 'approximated' => false, 'amount_details' => '', 'per_annum' => false, 'scv' => false, 'authors' => [ (int) 0 => |
# |
Jan 7th 2020, 18:54 |
this.impetus |
ok, so in reality I'm working on a Grants controller and shall hereafter stop pretending otherwise, because this is too big to both editing; I'm just pasting to the end of the first `author` record |
# |
Jan 7th 2020, 18:53 |
ndm |
no problem :) |
# |
Jan 7th 2020, 18:52 |
this.impetus |
... ndm please be patient with me I so in over my head; yeah I just dumped the request data again. sec |
# |
Jan 7th 2020, 18:52 |
ndm |
That looks like purely array data, not like an entity debug dump? At least the outer bounds should describe an object, and not be just `[]` |
# |
Jan 7th 2020, 18:51 |
this.impetus |
which as I understand it looks right, but then `$this->Publications->save()` |
# |
Jan 7th 2020, 18:50 |
this.impetus |
after patching: ```[ <publication fields> 'authors' => [ (int) 0 => [ '_joinData' => [ 'ordinance' => '1', 'principle_investigator' => 'false', 'starred' => '' ] ], (int) 1 => [ '_joinData' => [ 'ordinance' => '2', 'principle_investigator' => 'false', 'starred' => '' ] ] ] ]``` |
# |
Jan 7th 2020, 18:49 |
this.impetus |
I don't either! sec |
# |
Jan 7th 2020, 18:49 |
ndm |
I don't really understand what's failing... do you get any errors? What does `debug($publication)` show after patching? |
# |
Jan 7th 2020, 18:47 |
this.impetus |
I mean I simpler way to say this is that I want to create a new Publication, and at the same time save it's associated authors, and the join table needs two extra fields. I either don't know how to write that form, or else, if the sample data I provided appears correctly formatted, I'm failing on the controller end before the call to `Controller->save()` but I don't understand how. |
# |
Jan 7th 2020, 18:44 |
this.impetus |
The authors array arrives at the controller as shown, and the the last attempt at the `patchEntity` call is actually what's happening; still, the record isn't created and instead bounced back to controller/add |
# |
Jan 7th 2020, 18:43 |
this.impetus |
No, lol, sorry; the example I provided had mistakes, it was poor form of me because I modified it for chat and thus added those mistakes |
# |
Jan 7th 2020, 18:32 |
ndm |
Soooooo... it's working now? |
# |
Jan 7th 2020, 18:24 |
this.impetus |
... ok, to clarify, I need to use this logic for a bunch of different models, including `Grants`, which makes less immediate sense than `Publications`; again, this line isn't hot garbage in app and should have read: ```$publication = $this->Publications->patchEntity( $publication, $this->request->getData(), ['associated' =>['Authors']] );``` |
# |
Jan 7th 2020, 18:18 |
this.impetus |
Note: this isn't actually spelled wrong in my code, `$publication = $this->Publicationss` lol |
# |
Jan 7th 2020, 18:16 |
slackebot |
]``` to no avail. |
# |
Jan 7th 2020, 18:16 |
this.impetus |
I've also tried this ```'authors' => [ (int) 0 => [ '_joinData' => [ 'ordinance' => '1', 'principle_investigator' => 'false', 'starred' => 'true' ] ], (int) 1 => [ '_joinData' => [ 'ordinance' => '2', 'principle_investigator' => 'false', 'starred' => 'true' ] ], (int) 2 => [ '_joinData' => [ 'ordinance' => '3', 'principle_investigator' => 'false', 'starred' => 'true' ] ] |
# |
Jan 7th 2020, 18:13 |
this.impetus |
the form controls are dynamically generated, but I *think* I have them right, now, unless `_joinData[starred]` shouldn't have a value |
# |
Jan 7th 2020, 18:11 |
this.impetus |
and in my controller I have: ` ```$publication = $this->Publicationss->patchEntity( $grant, $this->request->getData(), ['associated' =>['Authors']] );```` |
# |
Jan 7th 2020, 18:11 |
slackebot |
'principle_investigator' => 'false', '_joinData' => [ 'starred' => 'true' ] ] ] ``` |
# |
Jan 7th 2020, 18:11 |
slackebot |
table has two extra fields. Here's the `authors` key of the request data : ```'authors' => [ (int) 0 => [ 'id' => '17', 'ordinance' => '1', 'principle_investigator' => 'false', '_joinData' => [ 'starred' => 'true' ] ], (int) 1 => [ 'id' => '7', 'ordinance' => '2', 'principle_investigator' => 'false', '_joinData' => [ 'starred' => 'true' ] ], (int) 2 => [ 'id' => '4', 'ordinance' => '3', |
# |
Jan 7th 2020, 18:11 |
this.impetus |
Heya guys, I was in here yesterday trying to figure out how make a form that would manage HABTM associations with more than the standard id fields. Got directed here: https://book.cakephp.org/3/en/views/helpers/form.html#creating-inputs-for-associated-data and made some headway. But I'm still failing to create the record when the aassocations are included. Just to make it easier to talk about, Publications HABTM Authors; but their join |
# |
Jan 7th 2020, 16:44 |
ndm |
no problem |
# |
Jan 7th 2020, 16:44 |
damiano |
perfect thank you! |
# |
Jan 7th 2020, 16:43 |
damiano |
ok |