CFormModel or CActiveRecord?

Hi:

I’ve researched this topic quite a bit on this forum and have also read the Definitive Guide but haven’t found a solution that applies to my particular situation, so I’ll appreciate any help I can get.

I’m starting to develop a multi tenant app where the relationship between users and tenants is MANY_MANY (that is, a user can belong to many tenants and a tenant can have many users):


tbl_users (1)---(M)> tbl_tenant_users <(N)---(1) tbl_tenants

What I want is a single user registration form that will create both the user and the tenant and will link them both through the associative table tbl_tenant_users.

While I have some idea of how to do it through a CFormModel to collect the data and then use DAO to manually store it in all 3 tables, I would prefer to use AR. The problem is I can’t figure out how will the associative table be updated with the primary keys of the users and tenant tables upon record creation. I believe I need something more that the relations() function in each model, but I don’t know what.

Any ideas? Thanks in advance.

Is not very clear what you mean, anyway I try to answer:

If those data will be saved in database, use ActiveRecord, not CFormModel.

You can collect data from many model following this example.

Thanks for your prompt answer @zaccaria. While replying to your post I’m beginning to understand better and I agree that I should use ActiveRecord.

I read the wiki article you mentioned before posting my question and it doesn’t address related models, much less a MANY_MANY relationship. The comment posted there by @jmcmasterj there does mention how to handle related models but not MANY_MANY which involves a third (associative) table which doesn’t contain user input data but rather the primary keys of the users and tenants tables. How and where do I update this third table?

Thanks again,