Permalink
Browse files

moved primary key mutator and accessors

  • Loading branch information...
mpscholten committed Oct 9, 2013
1 parent 8340659 commit 31b660bad836c0e6e2764563a6029307ec64ae33
@@ -0,0 +1,61 @@
+{% set primaryKeys = builder.table.primaryKeys %}
+
+{% if primaryKeys|length == 1 %}
+ /**
+ * Returns the primary key for this object (row).
+ * @return {{ primaryKeys[0].phpType }}
+ */
+ public function getPrimaryKey()
+ {
+ return $this->get{{ primaryKeys[0].phpName }}();
+ }
+{% elseif primaryKeys|length > 1 %}
+ /**
+ * Returns the composite primary key for this object.
+ * The array elements will be in same order as specified in XML.
+ * @return array
+ */
+ public function getPrimaryKey()
+ {
+ $pks = array();
+ {% for primaryKey in builder.table.primaryKeys %}
+ $pks[{{ loop.index0 }}] = $this->get{{ primaryKey.phpName }}();
+ {% endfor %}
+
+ return $pks;
+ }
+{% else %}
+ /**
+ * Returns NULL since this table doesn't have a primary key.
+ * This method exists only for BC and is deprecated!
+ *
+ * This "feature" is deprecated, since the getPrimaryKey() method is not required
+ * by the Persistent interface (or used by the templates).
+ *
+ * @return null
+ */
+ public function getPrimaryKey()
+ {
+ return null;
+ }
+{% endif %}
+
+/**
+ * Returns true if the primary key for this object is null.
+ * @return boolean
+ */
+public function isPrimaryKeyNull()
+{
+ {% if primaryKeys|length == 1 %}
+ return null === $this->get{{ primaryKeys[0].phpName }}();
+ {% else %}
+ return
+ {% for primaryKey in primaryKeys %}
+ (null === $this->get{{ primaryKey.phpName }}())
+
+ {% if not loop.last %}
+ &&
+ {% endif %}
+ {% endif %}
+ ;
+}
@@ -0,0 +1,41 @@
+{% set primaryKeys = builder.table.primaryKeys %}
+
+{% if primaryKeys|length == 1 %}
+ /**
+ * Generic method to set the primary key ({{ primaryKeys[0].name }} column).
+ *
+ * @param $ctype $key Primary key.
+ * @return void
+ */
+ public function setPrimaryKey($key)
+ {
+ $this->set{{ primaryKeys[0].phpName }}($key);
+ }
+{% elseif primaryKeys|length > 1 %}
+ /**
+ * Set the [composite] primary key.
+ *
+ * @param array $keys The elements of the composite key (order must match the order in XML file).
+ * @return void
+ */
+ public function setPrimaryKey($keys)
+ {
+ {% for primaryKey in builder.table.primaryKeys %}
+ $this->set{{ primaryKey.phpName }}($keys[{{ loop.index0 }}]);";
+ {% endfor %}
+ }
+{% else %}
+ /**
+ * Dummy primary key setter.
+ *
+ * This function only exists to preserve backwards compatibility. It is no longer
+ * needed or required by the Persistent interface. It will be removed in next BC-breaking
+ * release of Propel.
+ *
+ * @deprecated
+ */
+ public function setPrimaryKey($pk)
+ {
+ // do nothing, because this object doesn't have any primary keys
+ }
+{% endif %}

0 comments on commit 31b660b

Please sign in to comment.