Re: DataObjects Insert Problem
| From: | Leigh Caplan | Date: | Sun, 17 Nov 2002 00:05:45 +0000 |
| Subject: | Re: DataObjects Insert Problem | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-2744@lists.php.net to get a copy of this message | ||
Yeah, I manually generated all the classes and config files, because the autobuilder wouldn't work on the server. Thanks very much for the quick response, and the suggestions... I'll try overriding the insert() method.
Leigh
On Saturday, November 16, 2002, at 05:44 AM, Alan Knowles wrote:
mmh. - if you have manually altered the database.ini file to have two lines for [table__keys] I'm not sure what the results would be...Subject: DataObjects Insert Problem From: Leigh Caplan <maelman@u.washington.edu> Date: Sat, 16 Nov 2002 03:24:19 -0800 To: pear-general@lists.php.net Hi there... I'm having a bit of a problem using the insert() method on some of my objects. I'm manually setting the primary key, because it's actually two rows- both "user_id" and "order_id".it sounds like overrideing the insert method is probably the trick here.. function insert() { // do stuff to build order id and user id... parent::insert(); }So, I want the "user_id" field to stay consistent, but the "order_id" field should increment based on the contents of the "user_id" field. That way, orders will be numbered according to user, ie. user_id=1, order_id=1; user_id=1, order_id=2...user_id=2, order_id=1... etc...Im not 100% sure why, but they keys only currently supports single autoincrement type keys.. so adding more than one key would have unexpected results..Everything seems fine until I call the insert() method on my object... after this, its fields which are listed in the database.ini file as keys are reset to "0".if you are using mysql, it uses mysql_insert_id(), to make the return value for insert() (and sets the key column to match it..), otherwise it just uses the nextid() stuff from pear..I tried the same method on another type of object which uses an auto_increment field as its primary key, and the key was returned properly upon insert.I'm guessing it's the issue above.. - if you are setting the key manually, either remove it from the database Keys file.. (in which case static get may be less usefull).. or try overriding the insert() method function insert() { // do stuff to build order id and user id... $id = 'some calculated id'; $this->specialid = $id; parent::insert(); $this->specialid = $id; // reset id as it's }It should be noted that the data is properly inserted into the database, but the object variables corresponding to the primary key(s) are reset (I assume they're being passed NULL keys which are then cast to integers, the end result being variables assigned a value of zero).Regards AlanWhat could be causing this? I suppose I could keep copies of all my explicitly assigned keys and just put them into the object after it's inserted, but this would be a major kludge, and would defeat the purpose of simplifying my code (which is why I'm using dataobjects in the first place). Thanks in advance, Leigh Caplan maelman@u.washington.edu