I've used the field "id" with varchar type as PrimaryKey.

I only specified the ID as notEmpty in the $validate array.
Model::getLastInsertID() will not work but as you know that the ID is
varchar type you will be careful in your app. logic.

Try it, an let us know if you have problems.  And obviously, is better
if you use instead a sequence as ID .

On Mar 9, 3:34 am, brian <[email protected]> wrote:
> On Sun, Mar 8, 2009 at 10:02 PM, Son Dat Giang <[email protected]> wrote:
>
> > Suppose that the primary key of your table is "somekey" in varchar type. And
> > your model is SomeModel
> > In the define of SomeModel (somemodel.php), use the code:
> > $primaryKey = 'somekey';
> > In your add action, if you primary key's value is unique and randomized, use
> > this:
> > if($this->data)
> > {
>
> > $this->data['SomeModel'][$this->SomeModel->primaryKey] = 'your key value';
>
> > }
> > Else, if the value of primary key is submit from you form. You dont need to
> > do any thing.
>
> I've just been going through the source and I'm pretty sure that this
> wouldn't work. For starters, setting the PK in $data would mean not
> getting the 'created' field automatically  filled. I guess that could
> be done manually, as well.
>
> But, there would be problems with lastInsertId. With the MySQLi
> driver, for instance, this uses LAST_INSERT_ID() which is reliant upon
> an auto_increment field. Unless I've read this incorrectly, it looks
> like the PK must be auto_increment/serial. It looks like the only
> possible change from the convention is setting an alternative name
> with $primaryKey, not in the type of column.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to