Ejemplo n.º 1
0
	/**
	 * Sets a collection of AncienEtablissement objects related by a many-to-many relationship
	 * to the current object by way of the j_eleves_etablissements cross-reference table.
	 * It will also schedule objects for deletion based on a diff between old objects (aka persisted)
	 * and new objects from the given Propel collection.
	 *
	 * @param      PropelCollection $ancienEtablissements A Propel collection.
	 * @param      PropelPDO $con Optional connection object
	 */
	public function setAncienEtablissements(PropelCollection $ancienEtablissements, PropelPDO $con = null)
	{
		$jEleveAncienEtablissements = JEleveAncienEtablissementQuery::create()
			->filterByAncienEtablissement($ancienEtablissements)
			->filterByEleve($this)
			->find($con);

		$this->ancienEtablissementsScheduledForDeletion = $this->getJEleveAncienEtablissements()->diff($jEleveAncienEtablissements);
		$this->collJEleveAncienEtablissements = $jEleveAncienEtablissements;

		foreach ($ancienEtablissements as $ancienEtablissement) {
			// Fix issue with collection modified by reference
			if ($ancienEtablissement->isNew()) {
				$this->doAddAncienEtablissement($ancienEtablissement);
			} else {
				$this->addAncienEtablissement($ancienEtablissement);
			}
		}

		$this->collAncienEtablissements = $ancienEtablissements;
	}
Ejemplo n.º 2
0
	/**
	 * Removes this object from datastore and sets delete attribute.
	 *
	 * @param      PropelPDO $con
	 * @return     void
	 * @throws     PropelException
	 * @see        BaseObject::setDeleted()
	 * @see        BaseObject::isDeleted()
	 */
	public function delete(PropelPDO $con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(JEleveAncienEtablissementPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
		}

		$con->beginTransaction();
		try {
			$deleteQuery = JEleveAncienEtablissementQuery::create()
				->filterByPrimaryKey($this->getPrimaryKey());
			$ret = $this->preDelete($con);
			if ($ret) {
				$deleteQuery->delete($con);
				$this->postDelete($con);
				$con->commit();
				$this->setDeleted(true);
			} else {
				$con->commit();
			}
		} catch (Exception $e) {
			$con->rollBack();
			throw $e;
		}
	}