Hi all,
I have three tables,
product
-------
id int PK
code varchar
name varchar
unit varchar
category
-------
id int PK
code varchar
name varchar
product_category
---------------
id int PK
productFk FK to product(id)
categoryFk FK to category(id)
My relationship is
ProductCategory.php
Product.php
Category.php
Are they correct?
In addition,
1. how can I define the relation with through so that from product I can get its category?
2. how can I define the relation with through to get the first product sort by product name from the category?
Thanks in advance.
Daniel
I have three tables,
product
-------
id int PK
code varchar
name varchar
unit varchar
category
-------
id int PK
code varchar
name varchar
product_category
---------------
id int PK
productFk FK to product(id)
categoryFk FK to category(id)
My relationship is
ProductCategory.php
'category' => array(self::BELONGS_TO, 'Category', 'categoryFk'), 'product' => array(self::BELONGS_TO, 'Product', 'productFk'),
Product.php
'productCategory' => array(self::HAS_MANY, 'ProductCategory', 'productFk'),
Category.php
'productCategory' => array(self::HAS_MANY, 'ProductCategory', 'categoryFk'),
Are they correct?
In addition,
1. how can I define the relation with through so that from product I can get its category?
2. how can I define the relation with through to get the first product sort by product name from the category?
Thanks in advance.
Daniel