Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Does Propel allow optional foreign keys?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Murray Collingwood  
View profile  
 More options Jan 4 2012, 2:05 am
From: Murray Collingwood <mur...@focus-computing.com.au>
Date: Tue, 3 Jan 2012 23:05:01 -0800 (PST)
Local: Wed, Jan 4 2012 2:05 am
Subject: Does Propel allow optional foreign keys?

Hi folks

Does Propel allow optional foreign keys?

The documentation hints that this is true but it's not clear to me.

Consider a 'child' record which might have a 'parent' record but can exist
as an orphan when necessary.
To implement this I added: required="false" to the column definition.  The
documentation suggested this here:

and a LEFT JOIN for foreign keys attached to a non-required column


So I have a table with a non-required foreign key.

 <table name="ptbook" description="Identifies a booking">
  <column name="id" type="integer" required="true" primaryKey="true"
autoIncrement="true"/>
  <column name="staffid" type="integer" size="11" description="FK to user"
required="false"/>
  <foreign-key foreignTable="user" onDelete="CASCADE">
   <reference local="staffid" foreign="id"/>
  </foreign-key>
  ...
 </table>

When I generate the SQL it looks normal:

CREATE TABLE `ptbook`
(
    `id` INTEGER  NOT NULL AUTO_INCREMENT,
    `staffid` INTEGER(11)   COMMENT 'FK to user',
    ...
    PRIMARY KEY (`id`),
    INDEX `ptbook_FI_2` (`staffid`),
    CONSTRAINT `ptbook_FK_2`
        FOREIGN KEY (`staffid`)
        REFERENCES `user` (`id`)
        ON DELETE CASCADE
) ENGINE=InnoDB COMMENT='Identifies a booking';

However when I try inserting a booking without a staffid I get the error
message:

> [04-Jan-2012 17:01:13] PHP Fatal error:  Uncaught exception
> 'PropelException' with message 'Unable to execute INSERT statement [INSERT
> INTO `ptbook` (`ID`,`SLOTID`,`STAFFID`,`STUDENTID`,`SEATS`) VALUES
> (:p1,:p2,:p3,:p4,:p5)] [wrapped: SQLSTATE[23000]: Integrity constraint
> violation: 1452 Cannot add or update a child row: a foreign key constraint
> fails (`focus_sobs`.`ptbook`, CONSTRAINT `ptbook_FK_2` FOREIGN KEY
> (`staffid`) REFERENCES `user` (`id`) ON DELETE CASCADE)]' in
> /home/murray/dev/sobs2/build/propel/util/BasePeer.php:293

Propel version 1.5.6-dev

Please let me know if this is possible, otherwise what is the best option
for achieving this.

PS I have searched through the group archive and found similar messages,
but they were different problems.

Cheers
Murray


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Murray Collingwood  
View profile  
 More options Jan 4 2012, 6:28 pm
From: Murray Collingwood <mur...@focus-computing.com.au>
Date: Wed, 4 Jan 2012 15:28:36 -0800 (PST)
Local: Wed, Jan 4 2012 6:28 pm
Subject: Re: Does Propel allow optional foreign keys?

I just tried adding skipSql to the foreign key...

  <column name="staffid" type="integer" size="11" description="FK to user"

> required="false"/>
>   <foreign-key foreignTable="user" onDelete="CASCADE" skipSql="true">
>    <reference local="staffid" foreign="id"/>
>   </foreign-key>

Then trying "propel-gen sql" gives an error:

[PHP Error] DOMDocument::schemaValidate(): Element 'foreign-key', attribute

> 'skipSql': The attribute 'skipSql' is not allowed. [line 440 of
> /usr/share/php/data/propel_generator/lib/task/AbstractPropelDataModelTask.p hp]

Something isn't quite right here...

Cheers
Murray


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Francois Zaninotto  
View profile  
 More options Jan 9 2012, 4:05 pm
From: Francois Zaninotto <fzanino...@gmail.com>
Date: Mon, 9 Jan 2012 22:05:36 +0100
Local: Mon, Jan 9 2012 4:05 pm
Subject: Re: [propel] Re: Does Propel allow optional foreign keys?

Hi Murray,

You must use an old Propel version. The skipSQL attribute is taken into
account in the schema validation since Propel 1.6, see
https://github.com/propelorm/Propel/blob/master/generator/resources/x...
.

Cheers,

François

2012/1/5 Murray Collingwood <mur...@focus-computing.com.au>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »