Some of the form fields to one table, the rest to another

Hey guys,

this is probably very simple, but I am still not that much into the structure of Yii and its components.

I am trying to implement the scenario when, for instance, you have two types of registrations - one for firms, one for just persons. But, you know that they have something in common and this are mostly fields like username, password, email. I am planning to store them in the table "Users" and to create two more tables for each specific type of registration.

Is this a problem that needs to be solved by using $this->DbCommand(don't remember the exact syntax), or there is some trick that I miss at the moment?


You may read this article: http://everything2.c…l%2520databases

Qiang, thanks for the link. How is this implemented in Yii? I tried searching in the doc, but in fact, didn’t get exactly what I expected. I see it pretty easy to use queries with parameters, but want to find the best solution, if possible as so far, with Active record. So, the article mentions about creation of a new class, that will probably inherit the current. It’s a little bit late to think organization stuff now, but looking forward to hearing from you :).

The easiest way to go is to implement single-table inheritance. To do so, you just need to define a base AR class and override its instantiate() method to create an AR object whose class is based on a column value.

Class Table Inheritance is much more complex. There's no direct support for this in AR.

You might want to do it in a simple way by defining a form model, and let that one handle the logic and pushing the data to the right table models.

Yes, I am thinking of this. This part of the website is a task to my colleague in this project, so I will tell him when he gets home and will provide feedback.

Edit: What if I want to use transactions. Here's our problem. We have two types of registration, but fields like "username, password, email" are common and we store them in table "users". So, we must insert the data in this table "users" and select the last ID and use this ID as a connecting element in the second table "users_persons" and respectively the other for firms "users_firms". This should be secured by transaction. Although, the registration module isn't that overloaded, we should ensure proper execution.