Question

We have a table for articles, and a table for locale data for articles.

class Article_Model extends ORM {
    protected $has_many = array('article_translations');

[...]

class Article_Translation_Model extends ORM {

[...]

'articles_translations' table contain 'article_id', 'locale_id', 'heading', 'body', etc. columns.

Is it possible to do

SELECT article.id, article_translations.heading, article_translations.body
FROM articles
JOIN articles_translations ON (articles_translations.article_id = article.id)
WHERE articles_translations.locale_id = 'en_US.UTF-8'

using Kohana 2 ORM?

The ->with() construction works only for has_one relations. The articles_translations.article_id and articles_translations.locale_id is UNIQUE, of course.

Was it helpful?

Solution

You could go the other way though:

$article_translation = ORM::factory('article_translation')
    ->where('locale_id', 'en_US.UTF-8')
    ->find();

Then you can reference the article columns as:

$article_translation->body;
$article_translation->heading;
$article_translation->article->id;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top