This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use the new forum.
Home » support » symfony 1.3 and 1.4 » Mutual foreign keys might be confusing Propel 1.5?
Mutual foreign keys might be confusing Propel 1.5? [message #103410] Mon, 02 August 2010 13:11 Go to next message
halfer  is currently offline halfer
Messages: 9535
Registered: January 2006
Location: West Midlands, UK
Faithful Member
Hi all. More issues with Propel 1.5, although the problems may not be confined to that version. I am running Propel 1.5 + Oracle 10g + Symfony 1.3, on WinXP SP2, PHP 5.2.11.

I have the following schema, in which one table has a FK to a second, which in turn has a FK to the first. An Employee has a CTrainDepartment, which is led by a manager, who of course is an Employee. I've stripped out a lot of detail, and irrelevant tables, and it looks like this:

framework:
  _attributes:
    package: plugins.nfCTrainPlugin.lib.model
    defaultIdMethod: native

  EMPLOYEE:
    _attributes: { phpName: Employee, idMethod: native }
    EMP_ID: { phpName: EmpId, type: BIGINT, size: '22', scale: '0', primaryKey: true, required: true, autoIncrement: true }
    EMP_DEPT_ID: { phpName: DeptId, type: BIGINT, required: true, foreignTable: DEPARTMENT, foreignReference: DEPT_ID }
    EMP_CURRENT_ROLE_ID: { phpName: CurrentRoleId, type: BIGINT, size: '22', scale: '0', required: true, foreignTable: JOB_ROLE, foreignReference: ROLE_ID }
    EMP_BUS_UNIT_CODE: { phpName: BusUnitCode, type: VARCHAR, size: '6', required: true, foreignTable: BUSINESS_UNIT, foreignReference: BUS_UNIT_CODE }
    _indexes: { EMPLOYEE_PK: [EMP_ID] }

  JOB_ROLE:
    _attributes: { phpName: JobRole }
    ROLE_ID: { phpName: RoleId, type: BIGINT, size: '22', scale: '0', primaryKey: true, required: true }
    ROLE_BUS_UNIT_CODE: { phpName: BusUnitCode, type: VARCHAR, size: '6', required: false, foreignTable: BUSINESS_UNIT, foreignReference: BUS_UNIT_CODE }
    _indexes: { JOB_ROLES_PK: [ROLE_ID] }

  BUSINESS_UNIT:
    _attributes: { phpName: BusinessUnit }
    BUS_UNIT_CODE: { phpName: BusUnitCode, type: VARCHAR, size: '6', primaryKey: true, required: true }
    BUS_UNIT_LOC_ID: { phpName: LocationId, type: BIGINT, size: '22', scale: '0', required: false, foreignTable: LOCATION, foreignReference: LOC_ID }
    BUS_CONTRACT_CODE: { phpName: ContractCode, type: VARCHAR, size: 4, required: true, foreignTable: CONTRACT, foreignReference: CONTRACT_CODE }

  DEPARTMENT:
    _attributes: { phpName: CTrainDepartment, idMethod: native }
    DEPT_ID: { phpName: DeptId, type: BIGINT, primaryKey: true, required: true, autoIncrement: true }
    DEPT_LINE_MANAGER_EMP_ID: { phpName: LineManagerEmpId, type: BIGINT, foreignTable: EMPLOYEE, foreignReference: EMP_ID, required: true }
    DEPT_LOC_ID: { phpName: LocId, type: BIGINT, foreignTable: LOCATION, foreignReference: LOC_ID, required: true }

  LOCATION:
    _attributes: { phpName: Location }
    LOC_ID: { phpName: LocationId, type: BIGINT, size: '22', scale: '0', primaryKey: true, required: true }
    LOC_NAME: { phpName: Name, type: VARCHAR, size: '60', required: false }
    _indexes: { LOC_PK: [LOC_ID] }

  CONTRACT:
    _attributes: { phpName: Contract }
    CONTRACT_CODE: { phpName: Code, type: VARCHAR, size: '4', primaryKey: true, required: true }
    CONTRACT_NAME: { phpName: Name, type: VARCHAR, size: '60', required: false }
    _indexes: { CONTRACT_PK: [CONTRACT_CODE] }

The problem is that, when visiting a generated Propel module for Employee, when the EMP_DEPT_ID widget is rendered, it discovers that a function has been generated twice in the base department query class:

Fatal error: Cannot redeclare BaseCTrainDepartmentQuery::filterByEmployee() in ... symfony13-upgrade\plugins\nfCTrainPlugin\
lib\model\om\BaseCTrainDepartmentQuery.php on line 397

I am not certain that the mutual foreign keys are responsible for this issue, but I'd say it was a primary suspect.

Any ideas? Rolling Eyes

[Updated on: Mon, 02 August 2010 13:11]


Remember Palestine
Re: Mutual foreign keys might be confusing Propel 1.5? [message #103411 is a reply to message #103410 ] Mon, 02 August 2010 13:13 Go to previous messageGo to next message
halfer  is currently offline halfer
Messages: 9535
Registered: January 2006
Location: West Midlands, UK
Faithful Member
The replicated class looks like this:

	/**
	 * Filter the query by a related Employee object
	 *
	 * @param     Employee $employee  the related object to use as filter
	 * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
	 *
	 * @return    CTrainDepartmentQuery The current query, for fluid interface
	 */
	public function filterByEmployee($employee, $comparison = null)
	{
		return $this
			->addUsingAlias(CTrainDepartmentPeer::DEPT_LINE_MANAGER_EMP_ID, $employee->getEmpId(), $comparison);
	}

...

	/**
	 * Filter the query by a related Employee object
	 *
	 * @param     Employee $employee  the related object to use as filter
	 * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
	 *
	 * @return    CTrainDepartmentQuery The current query, for fluid interface
	 */
	public function filterByEmployee($employee, $comparison = null)
	{
		return $this
			->addUsingAlias(CTrainDepartmentPeer::DEPT_ID, $employee->getDeptId(), $comparison);
	}


Remember Palestine
Re: Mutual foreign keys might be confusing Propel 1.5? [message #103413 is a reply to message #103410 ] Mon, 02 August 2010 13:52 Go to previous messageGo to next message
halfer  is currently offline halfer
Messages: 9535
Registered: January 2006
Location: West Midlands, UK
Faithful Member
I've confirmed that if the key is taken out of DEPARTMENT, everything works fine and dandy:

  DEPARTMENT:
    _attributes: { phpName: CTrainDepartment, idMethod: native }
    DEPT_ID: { phpName: DeptId, type: BIGINT, primaryKey: true, required: true, autoIncrement: true }
    # If the below is set up as an FK to Employee (which it technically is) then we have two tables pointing
    # keys at each other, and this upsets the rendering of the "Employee.EMP_DEPT_ID" widget - since
    # Propel 1.5 incorrectly duplicates a method in BaseCTrainDepartmentQuery.php (I think one is
    # incorrectly named).
    #
    # Removed: foreignTable: EMPLOYEE, foreignReference: EMP_ID,
    DEPT_LINE_MANAGER_EMP_ID: { phpName: LineManagerEmpId, type: BIGINT, required: true }
    DEPT_LOC_ID: { phpName: LocId, type: BIGINT, foreignTable: LOCATION, foreignReference: LOC_ID, required: true }
    NAME: { phpName: Name, type: VARCHAR, size: 40, required: true }

I'll raise a ticket on the Propel mailing list, but comments are welcome from anyone who (a) has ideas for a proper fix or (b) has experienced this already.


Remember Palestine
Re: Mutual foreign keys might be confusing Propel 1.5? [message #103416 is a reply to message #103411 ] Mon, 02 August 2010 14:37 Go to previous messageGo to next message
xplo  is currently offline xplo
Messages: 428
Registered: September 2008
Faithful Member
if it was possible to add a relationName property it could have worked but i believe it s not ~

Propel should have added filterByEmployeRelatedByEmpId and filterByEmployeRelatedByDeptLineManagerEmptId so yes it s definitely a propel bug only for 1.5 .
Re: Mutual foreign keys might be confusing Propel 1.5? [message #103419 is a reply to message #103410 ] Mon, 02 August 2010 15:02 Go to previous messageGo to next message
halfer  is currently offline halfer
Messages: 9535
Registered: January 2006
Location: West Midlands, UK
Faithful Member
Thanks very much xplo, that's a great help. I will get it logged as a bug.

Edit: logged here.

[Updated on: Mon, 02 August 2010 16:57]


Remember Palestine
Re: Mutual foreign keys might be confusing Propel 1.5? [message #103435 is a reply to message #103410 ] Mon, 02 August 2010 19:26 Go to previous messageGo to next message
halfer  is currently offline halfer
Messages: 9535
Registered: January 2006
Location: West Midlands, UK
Faithful Member
Fixed already - this is a problem with stable (containing 1.5.1) but not trunk (containing 1.5.3-dev).

Smile


Remember Palestine
Re: Mutual foreign keys might be confusing Propel 1.5? [message #103438 is a reply to message #103435 ] Mon, 02 August 2010 20:24 Go to previous messageGo to next message
xplo  is currently offline xplo
Messages: 428
Registered: September 2008
Faithful Member
how does it generate the 2 method name with the fix ?
Re: Mutual foreign keys might be confusing Propel 1.5? [message #103467 is a reply to message #103410 ] Tue, 03 August 2010 10:40 Go to previous message
halfer  is currently offline halfer
Messages: 9535
Registered: January 2006
Location: West Midlands, UK
Faithful Member
The methods in question now look like this:

	/**
	 * Filter the query by a related Location object
	 *
	 * @param     Location $location  the related object to use as filter
	 * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
	 *
	 * @return    CTrainDepartmentQuery The current query, for fluid interface
	 */
	public function filterByEmployeeRelatedByLineManagerEmpId($employee, $comparison = null)
	{
		return $this
			->addUsingAlias(CTrainDepartmentPeer::DEPT_LINE_MANAGER_EMP_ID, $employee->getEmpId(), $comparison);
	}

...

	/**
	 * Filter the query by a related Employee object
	 *
	 * @param     Employee $employee  the related object to use as filter
	 * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
	 *
	 * @return    CTrainDepartmentQuery The current query, for fluid interface
	 */
	public function filterByEmployeeRelatedByDeptId($employee, $comparison = null)
	{
		return $this
			->addUsingAlias(CTrainDepartmentPeer::DEPT_ID, $employee->getDeptId(), $comparison);
	}

Much better Very Happy


Remember Palestine
Previous Topic:Doctrine csrf token required
Next Topic:sfGuardPlugin error: sfWidgetFormChoice does not support the following options: 'with_empty'
Goto Forum:
  

powered by FUDforum - copyright ©2001-2004 FUD Forum Bulletin Board Software