Get / save fileds on intermediate table

Hello community,

I have an issue handling extra fields from the intermediate table.

Look at the diagram:

I need to get all fields from the "PerfumeCategory" table, which is just an intermediate table between Perfumes and Categories. So relationship is defined as one Perfume can have many Categories.

Is Phalcon ORM capable of doing so?

So far we defined Perfume model as:

        $this->hasManyToMany('PerfumeID', 'PerfumeCategory','PerfumeID','CategoryID','Category', 'CategoryID', array('alias' => 'PerfumeCategory'));

and Category model as:

        $this->hasManyToMany('CategoryID', 'PerfumeCategory','CategoryID','PerfumeID','Perfume', 'PerfumeID', array('alias' => 'PerfumeCategory'));


36.3k

Look like my example, the table posts, tags, postsTags

        $this->hasManyToMany(
            'id',
            __NAMESPACE__ . '\PostsTags',
            'postsId',
            'tagsId',
            __NAMESPACE__ . '\Tags',
            'id',
            ['alias' => 'tag']
        );

See full source at https://github.com/phanbook/phanbook/blob/master/core/common/models/Posts.php#L624, if we defined relation as the above to get tags

posts->tags->id

You can take look code at https://github.com/phanbook/phanbook/blob/master/content/themes/default/partials/list-posts.volt#L29

edited Dec '15

Thanks.

But that's only the primary key of intermediate table, right?

How can you fetch other fields from the intermediate table, i.e. order in my diagram?

Also, how do you save the related data within intermediate table?