Login | Register
My pages Projects Community openCollabNet

Discussions > dev > Re: [propel-cvs] SVN update: r1043 - in branches/1.3: generator/classes/propel/engine/builder/om/php5 generator/classes/propel/engine/database/model generator/test/classes/propel runtime/classes/propel/util

propel
Discussion topic

Back to topic list

Re: [propel-cvs] SVN update: r1043 - in branches/1.3: generator/classes/propel/engine/builder/om/php5 generator/classes/propel/engine/database/model generator/test/classes/propel runtime/classes/propel/util

Reply

Author hlellelid
Full name Hans Lellelid
Date 2008-05-08 06:29:32 PDT
Message Well done, Ron -- great solution! :)

Hans

On Thu, 8 May 2008 13:27:20 +0000 (UTC), propel at svn dot phpdb dot org wrote:
> Author: ron
> Date: 2008-05-08 13:27:19 +0000 (Thu, 08 May 2008)
> New Revision: 1043
>
> Modified:
>
>
branches/1.3/generat​or/classes/propel/en​gine/builder/om/php5​/PHP5ObjectBuilder.p​hp
>
>
branches/1.3/generat​or/classes/propel/en​gine/builder/om/php5​/PHP5PeerBuilder.php​
> branches/1.3/generat​or/classes/propel/en​gine/database/model/​Table.php
> branches/1.3/generat​or/test/classes/prop​el/GeneratedObjectTe​st.php
> branches/1.3/runtime​/classes/propel/util​/Criteria.php
> Log:
> fix #624: creating objects with auto increment columns without setting
any
> fields
>
> Modified:
>
branches/1.3/generat​or/classes/propel/en​gine/builder/om/php5​/PHP5ObjectBuilder.p​hp
> ====================​====================​====================​=======
> ---
>
branches/1.3/generat​or/classes/propel/en​gine/builder/om/php5​/PHP5ObjectBuilder.p​hp 2008-05-07
> 13:05:36 UTC (rev 1042)
> +++
>
branches/1.3/generat​or/classes/propel/en​gine/builder/om/php5​/PHP5ObjectBuilder.p​hp 2008-05-08
> 13:27:19 UTC (rev 1043)
> @@ -496,6 +496,7 @@
> * @param string &$script The script will be modified in this
> method.
> **/
> protected function addConstructorBody(​&$script) {
> + $table = $this->getTable();
> $script .= "
> \$this->applyDe​faultValues();";
> }
> @@ -3389,21 +3390,19 @@
> ";
> } // foreach foreign k
> } // if (count(foreign keys))
> +
> + if ($table->hasAuto​IncrementPrimaryKey(​) ) {
> + $script .= "
> + if (\$this->isNew() ) {
> + \$this->modifiedColumns[] = " .
> $this->getColumn​Constant($table-​>getAutoIncrementPri​maryKey() ) . ";
> + }";
> + }
>
> $script .= "
>
> // If this object has been modified, then save it to the database.
> if (\$this->isModified()";
>
> - /*
> - FIXME: this doesn't work right now because the BasePeer::doInsert()
> method
> - expects to be passed a Criteria object that contains columns (which
> tell BasePeer
> - which table is being updated)
> - if ($table->hasAuto​IncrementPrimaryKey(​)) {
> - $script .= " || \$this->isNew()";
> - }
> - */
> -
> $script .= ") {
> if (\$this->isNew()) {
> \$pk = ".$this->getPeer​Classname()."::doIns​ert(\$this, \$con);";
>
> Modified:
>
branches/1.3/generat​or/classes/propel/en​gine/builder/om/php5​/PHP5PeerBuilder.php​
> ====================​====================​====================​=======
> ---
>
branches/1.3/generat​or/classes/propel/en​gine/builder/om/php5​/PHP5PeerBuilder.php​ 2008-05-07
> 13:05:36 UTC (rev 1042)
> +++
>
branches/1.3/generat​or/classes/propel/en​gine/builder/om/php5​/PHP5PeerBuilder.php​ 2008-05-08
> 13:27:19 UTC (rev 1043)
> @@ -1057,7 +1057,7 @@
> $cfc = $col->getPhpName();
> if ($col->isPrimaryKey() && $col->isAutoIncrement() &&
> $table->getIdMethod() != "none" && !$table->isAllowPkInsert()) {
> $script .= "
> - if (\$criteria->co​ntainsKey(".$this-​>getColumnConstant​($col).")) {
> + if (\$criteria->co​ntainsKey(".$this-​>getColumnConstant​($col).") &&
> \$criteria->key​ContainsValue(" . $this->getColumn​Constant($col) . ") ) {
> throw new PropelException('Cannot insert a value for auto-increment
> primary key ('.".$this->getC​olumnConstant($col)​.".')');
> }
> ";
>
> Modified:
> branches/1.3/generat​or/classes/propel/en​gine/database/model/​Table.php
> ====================​====================​====================​=======
> ---
>
branches/1.3/generat​or/classes/propel/en​gine/database/model/​Table.php 2008-05-07
> 13:05:36 UTC (rev 1042)
> +++
>
branches/1.3/generat​or/classes/propel/en​gine/database/model/​Table.php 2008-05-08
> 13:27:19 UTC (rev 1043)
> @@ -1325,6 +1325,24 @@
> }
>
> /**
> + * Gets the auto increment PK
> + *
> + * @return Column if any auto increment PK column
> + */
> + public function getAutoIncrementPrimaryKey()
> + {
> + if ($this->getIdMethod() != IDMethod::NO_ID_METHOD) {
> + $pks =$this->getPrimaryKey();
> + foreach ($pks as $pk) {
> + if ($pk->isAutoIncrement()) {
> + return $pk;
> + }
> + }
> + }
> + return null;
> + }
> +
> + /**
> * Returns all parts of the primary key, separated by commas.
> *
> * @return A CSV list of primary key parts.
>
> Modified:
> branches/1.3/generat​or/test/classes/prop​el/GeneratedObjectTe​st.php
> ====================​====================​====================​=======
> ---
>
branches/1.3/generat​or/test/classes/prop​el/GeneratedObjectTe​st.php 2008-05-07
> 13:05:36 UTC (rev 1042)
> +++
>
branches/1.3/generat​or/test/classes/prop​el/GeneratedObjectTe​st.php 2008-05-08
> 13:27:19 UTC (rev 1043)
> @@ -69,7 +69,7 @@
> $r = new Review();
> $this->assertEqu​als('2001-01-01', $r->getReviewDate('Y-m-d'));
>
> - $this->assertFal​se($r->isModifie​d(), "expected isModified() to be
> falseb");
> + $this->assertFal​se($r->isModifie​d(), "expected isModified() to be
> false");
>
> $acct = new BookstoreEmployeeAccount();
> $this->assertEquals(true, $acct->getEnabled());
> @@ -1009,4 +1009,14 @@
>
> $this->assertSame($cu, $cu2);
> }
> + /**
> + * Checks if it is allowed to save new, empty objects with a auto
> increment column
> + */
> + public function testAllowEmptyWithAu​toIncrement()
> + {
> + $bookreader = new BookReader();
> + $bookreader->save();
> +
> + $this->assertFal​se($bookreader->​isNew() );
> + }
> }
>
> Modified: branches/1.3/runtime​/classes/propel/util​/Criteria.php
> ====================​====================​====================​=======
> --- branches/1.3/runtime​/classes/propel/util​/Criteria.php 2008-05-07
> 13:05:36 UTC (rev 1042)
> +++ branches/1.3/runtime​/classes/propel/util​/Criteria.php 2008-05-08
> 13:27:19 UTC (rev 1043)
> @@ -323,6 +323,19 @@
> }
>
> /**
> + * Does this Criteria object contain the specified key and does it have
> a value set for the key
> + *
> + * @param string $column [table.]column
> + * @return boolean True if this Criteria object contain the
> specified key and a value for that key
> + */
> + public function keyContainsValue($column)
> + {
> + // must use array_key_exists() because the key could
> + // exist but have a NULL value (that'd be valid).
> + return (array_key_exists($column, $this->map) && ($this->map[$key] !==
> null) );
> + }
> +
> + /**
> * Will force the sql represented by this criteria to be executed
within
> * a transaction. This is here primarily to support the oid type in
> * postgresql. Though it can be used to require any single sql
> statement
>
>
> --------------------​--------------------​--------------------​---------
> To unsubscribe, e-mail: cvs-unsubscribe@prop​el.tigris.org
> For additional commands, e-mail: cvs-help at propel dot tigris dot org

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

Re: [propel-cvs] SVN update: r1043 - in branches/1.3: generator/classes/propel/engine/builder/om/php5 generator/classes/propel/engine/database/model generator/test/classes/propel runtime/classes/prop... hlellelid Hans Lellelid 2008-05-08 06:29:32 PDT
Messages per page: