2008年8月5日星期二

Re: [fw-db] Table Inheritance?

Do you have any sample code? I am not sure the best way to do this.


Bill Karwin wrote:
>
>
>
> Neil Garb wrote:
>>
>> There are a number of ways to do this. You could do the second insert
>> with code -- but if you're always inserting into the second table when
>> inserting into the first, you could use MySQL triggers.
>>
>
> There's no way for the trigger to know what to insert into the parent's
> `user_id` table.
>
> CREATE TRIGGER ins_val BEFORE INSERT ON validating_email
> FOR EACH ROW
> INSERT INTO validating (`key`, `user_id`, `creation_date`)
> VALUES (NEW.key, DEFAULT, NOW());
>
> I used DEFAULT for the user_id column, but otherwise you'd have to set up
> a MySQL session variable or something to do it.
>
> The better solution is to write a PHP class that uses both tables. Don't
> implement this as a function in either of your Table classes, but write a
> new class that encapsulates the application feature of allowing users to
> change and recover their account details. This logic does not belong in
> any one table class, it's really a feature that spans multiple table
> classes.
>
> Regards,
> Bill Karwin
>
>

--
View this message in context: http://www.nabble.com/Table-Inheritance--tp17716295p18841238.html
Sent from the Zend DB mailing list archive at Nabble.com.

没有评论: