How to add relation between curd and custom table


(Vinaya Maheshwari8) #1

I have created a curd using curd generation (with table status) in yii2-advanced application. and curd(create,view,edit,delete) is working properly.

Now I have created a new table relation (id, user_id, status_id) where user_id is the foreign key for user table and status_id is also foreign key for status table.

Now I want to update table relation on update status from backend.

For example :

  1. If one user (user_id is 1) creates new status then there will be a new entry in relation table like "relation (1, 1, {status_id just created by user})".

  2. if user delete status then the row with this status_id will also be removed from relation table.

  3. And these created status only visible to user_id 1 only not to other users (one user can only see his created status not to others).

I am new to this framework, so please guide me how to implement this scenario in my application?

Thanks in advance.


(swapn) #2

create own model for this table and write all rules which you want and set relation in function like has one ,has many