Skip to content
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

[Help] Tree/Node Behavior with Auto Increment? #366

Open
skrosoft opened this issue Sep 27, 2017 · 3 comments
Open

[Help] Tree/Node Behavior with Auto Increment? #366

skrosoft opened this issue Sep 27, 2017 · 3 comments

Comments

@skrosoft
Copy link

@skrosoft skrosoft commented Sep 27, 2017

Hello,

Is it posible to use auto-increment with the tree/node behavior?

If not, how can I have an ID before the persist call?

I get the following error:

You must provide an id for this node if you want it to be part of a tree.

Maybe the librarie should use PostUpdate to get the ID and finally generate the path.

Imposible to use this behavior for me, I have no ID before to persist my entities.

Do someone has any example of implementation of this behavior?

Thanks.

@skrosoft skrosoft changed the title Tree/Node Behavior with Auto Increment? [Help] Tree/Node Behavior with Auto Increment? Sep 27, 2017
@skrosoft

This comment has been minimized.

Copy link
Author

@skrosoft skrosoft commented Sep 27, 2017

Ok, I had to add the folowing function in my entity:

    /**
     * Get the node id
     *
     * @return int
     */
    public function getNodeId()
    {
        return is_null($this->id) ? -1 : $this->id;
    }

It appears work fine, of course, I have to persist the parent before to persist the child.

@Einenlum

This comment has been minimized.

Copy link

@Einenlum Einenlum commented Sep 28, 2017

Hi @skrosoft.

I'm not sure this library should bother with autoincrement issues.
One thing you can do to have an ID before persisting in database, is to generate an UUID into your code directly, instead of letting the database doing it.
Exposing an auto-increment ID is not considered as a good practice anyway.

This way, you guarantee a more secure way of storing IDs and at the same time, you keep the control of IDs out of the DB process.

@psren

This comment has been minimized.

Copy link

@psren psren commented Feb 28, 2018

@Einenlum exactly what I did.
The only change I had to do was changing the field because VARCHAR(255) was not enough.

/**
 * @ORM\Column(type="text")
 */
protected $materializedPath = '';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.