-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[Tree] lft, lvl, rgt always set to zero in an entity using Ulid as primary key. #2701
Comments
I tried to change the primary key type from Ulid to Uuid, the result is the same.
// src/Entity/Category.php
class Category implements Translatable
{
#[ORM\Id]
#[ORM\Column(type: UuidType::NAME, unique: true)]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\CustomIdGenerator(class: 'doctrine.uuid_generator')]
private ?Uuid $id = null; |
Hello, I have the same configuration, is there any solution. Or we need to switch back to My |
@kl3sk I still couldn't find a solution, nor succeed to patch the issue. For now I kept an |
I just find a solution that someone shared, It works for my first tests. Let me know for you. |
OK, I set up a test case for this, see main...mbabker:DoctrineExtensions:issue-2701 for that. I couldn't reproduce the issue with the lft/rgt values not being set right (this could very well be an SQLite versus another database platform issue), output below: $ vendor/bin/phpunit -c tests/ tests/Gedmo/Tree/Issue/Issue2701Test.php
PHPUnit 9.6.17 by Sebastian Bergmann and contributors.
1 "Food lft/rgt"
2 1
3 8
1 "Fruits lft/rgt"
2 2
3 3
1 "Vegetables lft/rgt"
2 4
3 7
1 "Carrots lft/rgt"
2 5
3 6 But, the test fails: 1) Gedmo\Tests\Tree\Issue\Issue2701Test::testGetNextSiblingsWithoutIdentifierMethod
Failed asserting that Array &0 (
0 => 'index [0], missing on tree root: 01HQM5N5P9FCKDHJ69XZX1DVH0'
) is true.
tests/Gedmo/Tree/Issue/Issue2701Test.php:90 Dumping some info from the query logger during that test, I see this query setting info on the root node: 16 => array:2 [
"message" => "Executing statement: {sql} (parameters: {params}, types: {types})"
"context" => array:3 [
"sql" => "UPDATE Category SET tree_root = ?, lvl = 0, lft = 1, rgt = 2 WHERE id = ?"
"params" => array:2 [
1 => Symfony\Component\Uid\Ulid {#360
#uid: "01HQM6B6QA4M459E41B3EHYG1E"
toBase58: "1C8fpHddgcTvCYdfyA4Wt5"
toRfc4122: "018de865-9aea-2508-54b8-8158dd1f402e"
time: "2024-02-27 02:29:49.418 UTC"
}
2 => Symfony\Component\Uid\Ulid {#360}
]
"types" => array:2 [
1 => 2
2 => 2
]
]
] The interesting bit here is the So, the extension needs to become a lot smarter when it comes to determining ID field types. How that happens, I can't say I've got a clue since I don't use UID-based PKs myself. #2216 (comment) might be an OK workaround in an application, but it's not going to be a great library-level solution (and it's only going to fix one specific use case). |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Hello @mbabker, Does it means it will not be revelent or it is still under consideration ? For now I use that trick Thanks |
Environment
Package
show
Doctrine packages
show
PHP version
Subject
I have nested Tree entity that implements Translatable and uses Ulid as primary keys.
The Entity's repository is CategoryRepository , it extends NestedTreeRepository.
src/Entity/Category.php
I created a test fixture using the basic example found in the documentation
src/DataFixtures/CategoryFixtures.php
After running the fixtures, I can see the following structure in DB:
You can notice that
lft
,lvl
andrgt
are set to 0 for all rows, instead of reflecting the expected structure.The text was updated successfully, but these errors were encountered: