Home » Database » DB_DataObject_FormBuilder » Bug #3650
processForm autodetect not sequence keys
Details
| Request #3650 | processForm autodetect not sequence keys |
|---|---|
| Submitted | 2005-02-28 20:43 UTC |
| From | abarrei at gmail dot com |
| Assigned | justinpatrin |
| Status | Wont fix |
| Package | DB_DataObject_FormBuilder |
| PHP Version | 4.3.8 |
| OS | Linux |
| Roadmaps | (Not assigned) |
Comments
[2005-02-28 20:43 UTC] abarrei at gmail dot com
Description:
------------
When you use not auto_increment keys, it says on the documentation that you could override that function to perform an additional check to see if an insert or and update should be perform.
I was thinking why this shouldn't be inside the class and so I would like to ask you that. as a query type: DB_DATAOBJECT_FORMBUILDER_QUERY_AUTODETECT should be able to detect and handle this situation.
I did the following in
* @version $Id: FormBuilder.php,v 1.119 2005/01/28 01:23:45 justinpatrin Exp $
Line: 2165
case DB_DATAOBJECT_FORMBUILDER_QUERY_FORCEUPDATE:
if ( $this->_do->update() === 0 )
{
$id = $this->_do->insert();
$this->debug('ID ('.$pk.') of the new object: '.$id.'<br/>');
break;
}
$this->debug('Object updated.<br/>');
break;
Is there any reason about why this was not included inside the class?
Greetings,
Ariel.=
[2005-02-28 22:32 UTC] abarrei at gmail dot com
I have already overrided the sequenceKey method to indicate there is no sequence key. What I meant is actually documented on the formbuilder processForm function. It is the situation when you don't have a sequence (or automatic generated key) so when formbuilder checks what to do, if update or insert, as the primary key is not empty (because you've filled it in your form, it tries to update a never inserted record.
According to DB_Dataobject class, the update() function returns FALSE on error, or a number of modified records on success. That's why I am using the === operator, so if the update() return 0, meaning success but no row modified, then it should be inserted.
Is it any clearer?
[2005-02-28 23:45 UTC] abarrei at gmail dot com
Yeah, I always use autoincremented ids. However, in the project I am working for, there are relationships that should be imported (CSV) using other db relationships that are not ids and I thought it was quicker and cleaner to do it this way, so I don't need to do all the conversions between their keys and my keys.
About having your primary key in the form, in this case the primary key is, as an example, your driver license, there is no problem detecting the key, the $do->keys() works ok, and I have the <var $fb_hidePrimaryKey = false;> on my DO and so I can fill the primary key in the form. I am not sure this isn't a normal way to do it, just a different way without using autoincs ids.
I thought this sceneario wasn't that strange, but may be I am wrong :)
Look at this part of the documentation of the processForm:
* <i><b>Careful:</b> If you're using natural keys or cross-referencing tables where you don't have
* one dedicated primary key, this will always assume that you want to do an update! As there
* won't be a matching entry in the table, no action will be performed at all - the reason
* for this behaviour can be very hard to detect. Thus, if you have such a situation in one
* of your tables, simply override this method so that instead of the key check it will try
* to do a SELECT on the table using the current settings. If a match is found, do an update.
* If not, do an insert.</i>
This is very simillar of what I talking about, but I was suggesting tu include that situation on the class instead of overriding it.
Sorry, I didn't mean to bother you with any philosphical discussion :)