Ticket #279 (closed enhancement: fixed)

Opened 4 years ago

Last modified 2 years ago

Add support for one-to-one relationships.

Reported by: hans Owned by: hans
Priority: normal Milestone: 1.3
Component: Generator Version: devel
Severity: normal Keywords: one-to-one relationship
Cc:

Description (last modified by hans) (diff)

Add support for one-to-one relationships in the builder classes. One-to-one relationships can be represented in an RDBMS by having the foreign key also be the primary key of a table.

<table name="users" phpName="User">
  <column name="id" type="INTEGER" primaryKey="true" autoIncrement="true"/>
  <!-- ... -->
</table>

<table name="profiles" phpName="Profile">
  <column name="uid" type="INTEGER" primaryKey="true"/>
  <foreign-key foreignTable="users">
    <reference local="uid" foreign="id"/>
  </foreign-key>
  <!-- ... -->
</table>

Currently in Propel a User->Profiles() method would be generated, but clearly there can only be one profile per user, since uid is the primary key. So, we should expect instead to have a User->getProfile() for relationships defined in this way.

Note, this could also apply to composite fkey and pkey columns.

Change History

comment:1 Changed 4 years ago by hans

  • Description modified (diff)

comment:2 Changed 4 years ago by hans

Added a basic implementation of this (only get method) in changeset:409

comment:3 Changed 4 years ago by hans

  • Status changed from new to closed
  • Resolution set to fixed
  • Milestone changed from 2.0 to 1.3

Added full & tested implementation to 1.3 branch in changeset:498. See wiki:Documentation/1.3/Relationships for documentation.

comment:4 Changed 4 years ago by apinstein

So this will cause BC-breakage when upgrading existing apps, right? Just wanted to be sure that if so, it's documented in a BC note for 1.3 somewhere...

comment:5 Changed 4 years ago by hans

That's correct; this will cause BC-breakage if you are currently using one-to-one relationships in Propel. Thanks for the reminder; I added a section on this to the upgrading document: wiki:Documentation/1.3/Upgrading

comment:6 Changed 3 years ago by joethong

  • Status changed from closed to reopened
  • Resolution fixed deleted

Could a column which is UNIQUE and has a FK but not necessarily a PK be justified as a 1-to-1 relationship?

comment:7 Changed 2 years ago by hans

  • Status changed from reopened to closed
  • Resolution set to fixed

Yes, I think the case could be made for that, though let's track that as a separate enhancement ticket.

Note: See TracTickets for help on using tickets.