additional fields in link table (ManyToMany)

Is it possible to have and access additional fields in join table for many to many relation?

For example table post_tag:


post_id

tag_id

created ---?

created_by ---?

I have a "tags many_many" table, that I use for multiple tables. Here is how i access the type (Blog, Album, Image etc).




'tags' 	=> array(self::MANY_MANY, 'Tag', 'TagMap(mapTo, tag)',

					'alias' => 'Tag',

					'on' => 'tags_Tag.type = :type',

					'params' => array(':type' => $this->tableName()))



So you can use the same for created and created_by.




'tags' 	=> array(self::MANY_MANY, 'Tag', 'TagMap(mapTo, tag)',

					'alias' => 'Tag',

					'on' => 'tags_Tag.type = :type',

					'params' => array(':type' => $this->tableName()))



So you can use the same for created and created_by.

[/quote]

Sorry, don’t get it. I think that’s not what I need. Maybe you provide an example of additional field?

I thought you wanted to use it in the relational query. But you want to access them after the query?

Like $post->post_tag->created_by ?

I don’t think you can do that.

yeah, I want to access directly. Ok thanks. Have to find another way.

You can’t access data from the join table directly. One workaround would be to create a model for this table (e.g. PostTag) and add another relation to Post. If you use the new index feature you can access this data by tag_id. So in Post you would add:


'posttags'=> array(self::HAS_MANY, 'PostTag', 'post_id', array('index'=>'tag_id')),

Then you can access the related PostTag object for a post and a given tag_id like this:


$post->posttags[$someTagID]

thanks Mike, will try.