-
Notifications
You must be signed in to change notification settings - Fork 418
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
deleting objects #656
deleting objects #656
Conversation
@marcj What do you say? You added most of the tests regarding #603. I wrote down any combination I could come up with, and as far as I can see, the only configuration determining whether to delete or save the related object(s) is The altered test case in @bacf915 fails without the change of @145c0a2. |
Hm, what happens to foreign keys where the local columns are not required? I believe they won't be deleted now with |
I just wrote a test and it passes. While writing it, I realized it's plain wrong, because the related object gets deleted - but not by Propel itself, but the database directly because of the |
I have no idea, how I could test this behavior, because of the |
You can use SQLite to check that, since we've not implemented there foreign keys yet. |
Well, then I can't check the foreign keys, can I? (see @f317ce2) |
Well, the actual mapping from the |
I will give it a try. |
The public function testDeleteCascade()
{
\MoreRelationTest\PagePeer::doDeleteAll();
\MoreRelationTest\ContentPeer::doDeleteAll();
$page = new \MoreRelationTest\Page();
$page->setTitle('Some important Page');
$content = new \MoreRelationTest\Content();
$content->setTitle('Content');
$page->addContent($content);
$page->save();
$this->assertEquals(1, \MoreRelationTest\ContentQuery::create()->count());
$page->delete();
$this->assertEquals(0, \MoreRelationTest\ContentQuery::create()->count());
} However, it passes with and without the changes of @f317ce2. Am I missing something here? |
Have you flagged the columns of the foreign key as required? |
I thought they should be not required but cascade? Null is valid, but they should be deleted. |
I tried it in our project, the mentioned changes are indeed required and result in the expected generated code, but still no valid test case to verify this. :( |
Yes, they should not be required to test that, that's why I ask. :) |
That's the case :) I'm using this schema: https://github.com/propelorm/Propel/blob/master/test/testsuite/generator/builder/om/GeneratedObjectMoreRelationTest.php#L31-L66 |
Ok, a test like that shows the issue with having no public function testOnDelete(){
\MoreRelationTest\PagePeer::doDeleteAll();
\MoreRelationTest\ContentPeer::doDeleteAll();
$page = new \MoreRelationTest\Page();
$page->setTitle('Some important Page');
$content = new \MoreRelationTest\Content();
$content->setTitle('Content');
$page->addContent($content);
$page->save();
$this->assertEquals(1, \MoreRelationTest\ContentQuery::create()->count());
$page->removeContent($content);
$page->save();
$this->assertEquals(0, \MoreRelationTest\ContentQuery::create()->count());
} |
But you are not deleting the page. |
Ah wait, I see what you are doing there, thank you! |
An object that is related to another one where this relation is required is meant to be deleted by Propel to ensure its behavior upon deletion. If the relation is not required, but the foreign key defines a CASCADE behavior on deletion, the object will also be deleted.
Added, rebased, squashed. |
The only thing now is that https://github.com/propelorm/Propel/pull/656/files#L0R4317 makes the only change in the test result of |
Because the attribute is not used, but only generated. Therefore I added the same condition where required, see https://github.com/havvg/Propel/blob/3bf0689decf37195148e948ca86151b9bc470e3e/generator/lib/builder/om/PHP5ObjectBuilder.php#L4790 |
ok, perfect! nice job 👯 |
Cool, thanks for the review! Ping @willdurand |
great job guys! 👍 |
thx guys! |
see #636, #603