Hey guys, I need our help.
I have 2 database tables - categories
and categories_description
.
CREATE TABLE `categories` (
`id` int(11) NOT NULL,
`route` int(3) NOT NULL,
`sort_order` int(3) NOT NULL DEFAULT '0',
`active` char(1) NOT NULL DEFAULT 'Y',
`createAt` datetime NOT NULL,
`updateAt` datetime NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE `categories_description` (
`id` int(11) NOT NULL,
`category_id` int(11) NOT NULL,
`language_id` int(11) NOT NULL,
`name` varchar(255) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
class Categories extends \Phalcon\Mvc\Model
{
/**
* Initialize method for model.
*/
public function initialize()
{
$this->hasOne('id', __NAMESPACE__ . '\CategoriesDescription', 'category_id', [
'alias' => 'description',
'foreignKey' => [
'action' => Model\Relation::ACTION_CASCADE
]
]);
}
}
class CategoriesDescription extends \Phalcon\Mvc\Model
{
/**
* Initialize method for model.
*/
public function initialize()
{
$this->belongsTo('category_id', __NAMESPACE__ . '\Categories', 'id', [
'alias' => 'categories'
]);
}
}
So far so good.
// category with id=1
$category = Categories::find(1);
// give all descriptions
$descriptions = $category->description;
// description with language_id=5 from category
$description = $category->???;
How do I get the data of one language, e.g: language_id=5?