Having the following structure:
<?php
namespace App\Core\Models\Post;
class Post extends \App\Core\Models\CoreModel
{
public function initialize()
{
$this->hasManyToMany(
"id",
"App\Core\Models\Post\PostSignaturePost",
"post_id",
"signature_id",
"App\Core\Models\Signature\Signature",
"id",
array(
'alias' => 'signatures'
)
);
}
}
<?php
namespace App\Core\Models\Post;
class PostSignaturePost extends \App\Core\Models\CoreModel
{
public function initialize()
{
$this->belongsTo('signature_id', 'App\Core\Models\Signature\Signature', 'id',
array('alias' => 'signature')
);
$this->belongsTo('post_id', 'App\Core\Models\Post\Post', 'id',
array('alias' => 'post')
);
}
}
<?php
namespace App\Core\Models\Signature;
class Signature extends \App\Core\Models\CoreModel
{
public function initialize()
{
$this->hasManyToMany(
"id",
"App\Core\Models\Post\PostSignaturePost",
"signature_id",
"post_id",
"App\Core\Models\Post\Post",
"id",
array('alias' => 'posts')
);
}
}
Questions:
-
If i call $post->signatures->delete() will delete signatures from signature table, not from the intermediate table. If this is a bug, this is HUGE and needs fix ASAP. If it's not a bug, then ?
- The proper way to update the signatures for a post ? What would be ? Example:
A) a post has N signatures. I want remove one. How ? Normally, if i pass the id's in orm should be enought. But it's not.
$post = PostObject();
$signatures = SignaturesObject::find(array("id in (".implode(',', $post_data['signatures']).")");
// If i say
$post->signatures = $signatures;
$post->update();// it is not working. The ORM especially on update should remove all the non-related signatures and save the new ones.
//If i say
foreach ($post->signatures as $sig) { // maybe ORM should handle this ?
$to_save[] = $sig;
}
$post->signatures = $to_save;
$post->update(); // It works, but does not remove the old ones.
// If is say
$post->signatures->delete(); // BUG ?! Removes the signatures from the signature table, not from the intermediate table
$post->signatures = $to_save[];
$post->save();
And again a bug that i opened months ago https://github.com/phalcon/cphalcon/issues/2039 and none really cares, but in the meanwhile bugs like image processing were fixed ...