Пример #1
0
	/**
	 * Sets a collection of Classe objects related by a many-to-many relationship
	 * to the current object by way of the j_groupes_classes 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 $classes A Propel collection.
	 * @param      PropelPDO $con Optional connection object
	 */
	public function setClasses(PropelCollection $classes, PropelPDO $con = null)
	{
		$jGroupesClassess = JGroupesClassesQuery::create()
			->filterByClasse($classes)
			->filterByGroupe($this)
			->find($con);

		$this->classesScheduledForDeletion = $this->getJGroupesClassess()->diff($jGroupesClassess);
		$this->collJGroupesClassess = $jGroupesClassess;

		foreach ($classes as $classe) {
			// Fix issue with collection modified by reference
			if ($classe->isNew()) {
				$this->doAddClasse($classe);
			} else {
				$this->addClasse($classe);
			}
		}

		$this->collClasses = $classes;
	}
Пример #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(JGroupesClassesPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
		}

		$con->beginTransaction();
		try {
			$deleteQuery = JGroupesClassesQuery::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;
		}
	}