We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Create() fails on models with relations using composite primary keys

Hallo All

This is a kind of repost, as i can't figure out the correct answer from similar posts. post1 post2

I'm not able to run a create() on models with composite primary keys. The relations are defined as follows:

$this->hasMany(array('id','company_id'), 'Multiple\Backend\Models\Subscription', array('store_id','company_id'), array('alias' => 'Subscription'));
$this->belongsTo(array('store_id','company_id'), 'Multiple\Backend\Models\Store', array('id','company_id'), array('alias' => 'Store'));

I get the error

Not implemented; File = phalcon/mvc/model.zep; Line = 2640

Is this possible to run a create whit this model definition and if yes what do i do wrong? I'm runnings phalcon 2.0.9 on ubuntu.

Thanks in advance

https://github.com/phalcon/cphalcon/blob/master/phalcon/mvc/model.zep

As you see, this relation with array is not yet implemented.

If you look in the link post1, then Phalcon reply to a post with similar problems

I think only many-to-many relations with composite keys could throw that exception, create()/update()/save() must work on composite keys without problem

My understanding of this, is that this should be (or has been) possible. Is this removed in the current version or do I misunderstand something here?

Thanks.