-
Notifications
You must be signed in to change notification settings - Fork 399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix issue #1388: broken model-only relationships #1389
Open
Alexander-Bliznyuk
wants to merge
2
commits into
propelorm:master
Choose a base branch
from
Alexander-Bliznyuk:fix-skipSql
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
/** | ||
* This file is part of the Propel package. | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @license MIT License | ||
*/ | ||
namespace Propel\Tests\Issues; | ||
|
||
use Propel\Generator\Util\QuickBuilder; | ||
use Propel\Tests\TestCaseFixtures; | ||
|
||
/** | ||
* Test : Propel should allow marked to be skipped foreign key references on table with composite primary key | ||
* @group model | ||
*/ | ||
class Issue1388Test extends TestCaseFixtures | ||
{ | ||
public function testSkippedIncompleteForeignReference() | ||
{ | ||
$schema = <<<EOF | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<database name="test" defaultIdMethod="native"> | ||
<table name="event"> | ||
<column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" /> | ||
<column name="name" type="varchar" size="50" required="true" /> | ||
<column name="organiser_type_id" type="integer" required="true" /> | ||
<!-- This FK is incomplete --> | ||
<foreign-key foreignTable="organiser" skipSql="true"> | ||
<reference local="organiser_type_id" foreign="type_id" /> | ||
</foreign-key> | ||
</table> | ||
|
||
<table name="organiser"> | ||
<!-- Has composite PK --> | ||
<column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" /> | ||
<column name="secondary" type="integer" required="true" primaryKey="true" /> | ||
<column name="type_id" type="integer" required="true" /> | ||
<column name="name" type="varchar" size="50" required="true" /> | ||
</table> | ||
</database> | ||
EOF; | ||
|
||
$builder = new QuickBuilder(); | ||
$builder->setSchema($schema); | ||
|
||
try { | ||
$builder->buildClasses(null, true); | ||
$noExceptionThrown = true; | ||
} catch (\Exception $e) { | ||
$noExceptionThrown = false; | ||
} | ||
|
||
$this->assertTrue($noExceptionThrown); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When an exception is thrown this test is automatically marked as failed, so no need for that assertTrue :) |
||
|
||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, generating SQL has nothing to do with checking for valid foreign keys. So this check is a misuse of the
skip-sql
attribute to allow models generation with invalid foreign keys.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Propel used to allow flexible models tailored for application's needs. This checking for foreign keys merely ties hands. For example, if referent table has composite key, it appears to be impossible to join it by a column outside the key.
Please also consider fully justified and common scenario: i18n tables having primary key(id, locale). Of course in many cases other tables would refer to i18n tables only by id. Another similar common scenario is versioning of entities.
Maybe it's ok to be strict and thus guarantee scheme validity between different RDBMS and to guide amateurs.
But model only relationships feature shouldn't be broken. It doesn't work now as described in docs and my pull request fixes this regression.