Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

How To Define Relation With Through

$
0
0
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
'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

Viewing all articles
Browse latest Browse all 18717

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>