Hi! I have 3 tables (models) News Tags NewsTags
When Im making many-to-many relations, I can easily get tags from news item. But how can I get news from tag item?
news
<?php
$this->hasManyToMany(
"id",
"NewsToTags",
"news_id", "tag_id",
"Tags",
"id",
array('alias' => 'NewsToTags')
);
tags
<?php
$this->hasManyToMany(
"id",
"NewsToTags",
"tag_id", "news_id",
"News",
"id",
array('alias' => 'news')
);
newstotags
<?php
$this->belongsTo("news_id", "News", "id", array('alias' => 'news'));
$this->belongsTo("tag_id", "Tags", "id", array('alias' => 'tags'));
Im getting very nicely the tags from news item
<?php
foreach ($news->NewsToTags as $NewsTag) {
$tags[$NewsTag->id] = $NewsTag->name;
}
But I cant get in same way news from tag item.
Question:
-
Is im doing right (the docs are a bit not much clear for me)
-
How to get news from tag item (the best way)?
- Can I get not all columns but only for example id and name in the code above?