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

Insert into realtionship

I would like to know, how I insert a new item to the relationship, and also include the "themeId" into the themeVersion:

    $theme = new Themes();

        $name = $this->request->getPost("name");


        $version = new Version();

        echo $theme->getThemeId(); // How do i get my theme_id, so i can insert it into the version?


        $theme->version = $version;

You need to save it into database. DB will return incremental ID, which you can after use for another models.

$theme = new Themes();

$theme->getId(); // Or depends how you called your primary key


I know, but then i though it would be possible to save the version with the themeid and insert them together like my current example

edited Mar '20

Assuming you have set up the Theme <-> Version relationship like this:


public function initialize(){


public function initialize(){

then you don't need to do anything. Phalcon will auto-assign the correct Themes.id to the new Version when saving.

edited Mar '20

Thanks for your reply.

I will look into it as soon as I am able to!


i would like to add that $theme->getThemeId(); is identical to $theme->theme_id;

it can differ if you set the propery theme_id visibility to public and in the same time declared getters and setters in the model