Re: DB_Object->update() : "getLink: row not set"

From: Date: Wed, 17 Nov 2004 18:22:57 +0000
Subject: Re: DB_Object->update() : "getLink: row not set"
References: 1 2 3 4 5  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-15601@lists.php.net to get a copy of this message
On Tue, 16 Nov 2004 19:24:07 -0800, Ken Restivo <ken@restivo.org> wrote: > I'd like to see an example of the recommended way to insert links using DB_Object. I have > an app with lots of this kind of stuff: > > create table table_a ( > table_a_pkey int(32) not null unique auto_increment, > col1 varchar(255), > col2 varchar(255), > col3 varchar(255), > primary key (table_a_pkey) > ); > > create table table_b ( > table_b_pkey int(32) not null unique auto_increment, > col4 varchar(255), > col5 varchar(255), > col6 varchar(255), > table_a_pkey int(32), > primary key (table_b_pkey) > ); > > create table table_c ( > table_c_pkey int(32) not null unique auto_increment, > col7 varchar(255), > col8 varchar(255), > col9 varchar(255), > table_b_pkey int(32), > primary key (table_c_pkey) > ); > > Where the links are like > > [table_c]: > table_b_pkey: table_b:table_b_pkey > > [table_b]: > table_a_pkey: table_a:table_a_pkey > > And I often have to insert data into tables a, b, and c all in one go, and maintain the links > in what I just inserted. > > So I need to insert table_a's data, then get the last_insert_id(), then insert > table_b's data along including the table_a_pkey, and get its last_insert_id(), then insert > table_c including the table_b_pkey. > > In the application I am porting to PEAR, I wrote my own customised database abstraction which > did exactly that at insert time. Works great but it is based on a model so different from DB_Object > that I basically can't use any of it and would need to start from scratch. Besides, bluntly, my > code sucks, and I'd rather use someone else's if it is available. > > I don't want to reinvent the wheel and want to do it in the most PEAR-like way possible. > Is there a clean way to do it in a generic way with DB_Object? > First of all, there's a package called DB_DataObject_FormBulder (I'm a lead on it) that will auto-create HTML_QuickForm forms for you from a DataObject. It handles insertion, deletion, and multiple types of fields, including links. It also allows great customization of the forms through many options. If you need to get the last_insert_id(), DB_DataObject will do this for you. After you insert(), the key field should have the new id in it. If you want to insert to multiple table sin one form, I just added some stuff to FormBuilder to do that. Hopefully it will work for you. -- Justin Patrin

« previous php.pear.general (#15601) next »