Re: DB_DataObject_formbuilder sequence
| From: | Justin Patrin | Date: | Wed, 05 Jan 2005 08:45:00 +0000 |
| Subject: | Re: DB_DataObject_formbuilder sequence | ||
| References: | 1 2 3 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-16633@lists.php.net to get a copy of this message | ||
On Wed, 05 Jan 2005 13:53:17 +0530, Jacob Singh <jacob@pajamadesign.com> wrote:
> Justin Patrin wrote:
> > On Wed, 05 Jan 2005 00:35:49 +0530, Jacob Singh <jacob@pajamadesign.com> wrote:
> >
> >>I'm using sequences in application and I want to specify the primary key
> >>value before inserting the data using the Formbuilder. Where do i do
> >>this. it never seems to set correctly.
> >
> >
> > If you implemented a sequence all your own you're going to have to
> > look into the sequenceKey() call. I would recommend using a sequence
> > in the DB itself or allowing DB to handle the sequence. Both shoudl
> > work with DB_DataObject.
> >
> >
> I tried looking into this, but to no avail. I'm using Seagull, and we
> have a sequence table. Code elsewhere in the framework is something like:
>
> $dbh = $myDO->getDatabaseConnection();
> $nextId = $dbh->nextId($tablename);
>
> $myDO->primary_key = $nextId;
> $myDO->otherfield = "foobar";
> $myDO->insert();
>
> Is this "in the DB itself" or do I need sequenceKey()? I tried playing
> around with sequence key, but it's not working. It doesn't set
> anything. Plus, I guess it would need to be set after FB is called, but
> before the form object is generated and the process method is called.
> Is this correct? It doesn't work now.
So you're doing it with DB, then. This should do it:
$myDO->sequenceKey('primary_key', false, false);
Replace primary_key with the name of your primark key column. This has
to be done on the DO before you use that table for anything. You can
also override the sequenceKey method in the DO to return
array('primary_key', false, false), which would alleviate the need for
the above:
class DataObject_MyDo extends DB_DataObject {
//...
function sequenceKey() {
return array('primary_key', false, false);
}
}
You should also be able to set this in your DataObject.ini:
sequence_tablename = primary_key
Where tablename is the name of the table and primary_key is the name
of the primary key.
>
> Thanks
> Jacob
>
>
> >>Thanks
> >>Jacob
> >>
> >
> >
>
--
Justin Patrin