Hi I have a form with only few properties of a model, and I want that model only update these fields.
I made this update call
return $chapter->update($chapter, [ 'name', 'number', 'subNumber', 'visibility', 'teams' ]);
to update only these listed fields (
teams is the alias of a relationship)
My problem is, when I update the model, I have a message saying
createdAt is required.
createdAt is not in the Form, so there is no value for this, okay, but I don't want to update it, I didn't list it in the whitelist.
To test I dleted the NotNull on the column and It "worked", but the field is now NULL ...
Other problem is, I have another column
deleted is set to NULL too.
I don't understand this problem...
edit : After some tests, I saw that the relationships
teams recreate a new line in the joint table each updates. ..
Here is how the relationship is declared
$this->hasManyToMany( 'id', ChapterTeams::class, 'chapterId', 'teamsId', Teams::class, 'id', [ 'alias' => 'Teams' ] );
$this->hasManyToMany( 'id', Teams::class, 'teamsId', 'chapterId', ChapterTeams::class, 'id' );
$this->setSource('chapter_teams'); $this->belongsTo( 'chapterId', Chapter::class, 'id' ); $this->belongsTo( 'teamsId', Teams::class, 'id' );
I don't understand how this can work like that ...
Edit 2 :
Now I try to delete the existing relationship with
$chapter->teams->delete() but it doesn't do anything (return false and no messages in
So I'm completely stuck, the relation is duplicated each update (I added a unique constraint on the both fields to prevent that and I now have a fatal error).
I don't understand how to handle the relations in Phalcon and the docs is pretty poor about that.
Phalcon seems poor with its built-in ORM/ODM, If every request need to be done in pure SQL to be correct and/or to be working, There is no interest in that.
Edit 3 : So to resume all my problems how to handle update model with relationship (with a "relation table") (the relation is mangaed with a multi select in a Form) :
- Do I need to delete the relationship (in 3rd table) and then re add them ? in this case, how to delete the relation ?
- is there a way that automatically handle addition/deletion in relationship ? Like, I get my object (Chapter) that have one or more Teams. in the Form, the multiselect is filled with existing teams in Chapter. When I submit the form, automatically watch the ChapterTeams relationship and add/delete if needed (if the relation already exist, nothing to do).
Thanks in advance to help me with this, it's completely blocking for my app ^^"