*** How Set Relation On This Tables ***

hello guys

how can i set relation in AR for attached tables

upcity.ir/images/38387549103252132631.jpg

thanks

Do you mean like two tables.

If that is the case lets take categories and products.

So the relationship is products model will be




public function relations()

    {

    // NOTE: you may need to adjust the relation name and the related

    // class name for the relations automatically generated below.

    return array(

    'category' => array(self::BELONGS_TO, 'Categories', 'category_id'),

    );

    }



category_id belongs categories.

And in category model we have.




public function relations()

    {

    // NOTE: you may need to adjust the relation name and the related

    // class name for the relations automatically generated below.

    return array(

    'product' => array(self::HAS_MANY, 'Products', 'category_id'),

    );

    }



Shows the products table has many category_id.

The easiest way is to create the database table and gii will generate for you.