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

Allow the tags to work with uuids #2087

Open
jeroendesloovere opened this Issue Jun 12, 2017 · 5 comments

Comments

Projects
None yet
3 participants
@jeroendesloovere
Member

jeroendesloovere commented Jun 12, 2017

Type

Enhancement

Problem description

You can now only use integers as id's for the tags, if switched to strings we can use UUID's

Why?

When creating modules with Doctrine entities and UUID,
$id is char(36) in combination with (DC2Type:guid).

So using the current tags module will not be possible anymore for these custom modules,
since it requires the $otherId to be an int and we have a char...

// save the tags
BackendTagsModel::saveTags(int $otherId, $tags, string $module, string $language = null)

Related issue with same problem

"Search to work with uuids": #1962

@tijsverkoyen

This comment has been minimized.

Show comment
Hide comment
@tijsverkoyen

tijsverkoyen Jun 12, 2017

Member

Can you explain why? And an example on why you need this?

Member

tijsverkoyen commented Jun 12, 2017

Can you explain why? And an example on why you need this?

@jeroendesloovere

This comment has been minimized.

Show comment
Hide comment
@jeroendesloovere

jeroendesloovere Jun 12, 2017

Member

Why?

When creating modules with Doctrine entities and UUID,
$id is char(36) in combination with (DC2Type:guid).

So using the current tags module will not be possible anymore for these custom modules,
since it requires the $otherId to be an int and we have a char...

// save the tags
BackendTagsModel::saveTags(int $otherId, $tags, string $module, string $language = null)

Related issue with same problem

"Search to work with uuids": #1962

Member

jeroendesloovere commented Jun 12, 2017

Why?

When creating modules with Doctrine entities and UUID,
$id is char(36) in combination with (DC2Type:guid).

So using the current tags module will not be possible anymore for these custom modules,
since it requires the $otherId to be an int and we have a char...

// save the tags
BackendTagsModel::saveTags(int $otherId, $tags, string $module, string $language = null)

Related issue with same problem

"Search to work with uuids": #1962

@carakas

This comment has been minimized.

Show comment
Hide comment
@carakas

carakas Jun 12, 2017

Member

@tijsverkoyen I've also ran into this issue, and this combined with the search module is the main reason I'm not using them more often. Since if you want that to work you need to add a separate id just for this. Kinda overkill

Member

carakas commented Jun 12, 2017

@tijsverkoyen I've also ran into this issue, and this combined with the search module is the main reason I'm not using them more often. Since if you want that to work you need to add a separate id just for this. Kinda overkill

@carakas

This comment has been minimized.

Show comment
Hide comment
@carakas

carakas Jun 12, 2017

Member

@jeroendesloovere can you update the issue description so it contains the reasons why that you added in your comment?

Member

carakas commented Jun 12, 2017

@jeroendesloovere can you update the issue description so it contains the reasons why that you added in your comment?

@carakas carakas removed the Nice to have 5 label Aug 1, 2017

@carakas carakas modified the milestones: 6.0.0, 5.0.0 Aug 1, 2017

@carakas

This comment has been minimized.

Show comment
Hide comment
@carakas

carakas Aug 2, 2017

Member

For now you can fix it with something like this

Entity

    /**
     * @var string
     *
     * @ORM\Id()
     * @ORM\GeneratedValue(strategy="UUID")
     * @ORM\Column(type="guid")
     */
    private $id;

    /**
     * @var int
     *
     * we need this since the tag index only works with integers
     *
     * @ORM\Column(type="integer")
     */
    private $tagId;

    /**
     * @param int $tagId
     *   …
     */
    public function __construct(
        $tagId
        
    ) {

Creating new instance of entity

        $myEntity = new MyEntity(
            $this->myEntityRepository->getNextTagId(),

        );

Repository

    public function getNextTagId(): int
    {
        return (int) $this->getEntityManager()->createQueryBuilder()
            ->select('(COALESCE(MAX(e.tagId), 0) + 1) AS tagId')
            ->from(MyEntity::class, 'e')
            ->getQuery()
            ->getSingleScalarResult();
    }
Member

carakas commented Aug 2, 2017

For now you can fix it with something like this

Entity

    /**
     * @var string
     *
     * @ORM\Id()
     * @ORM\GeneratedValue(strategy="UUID")
     * @ORM\Column(type="guid")
     */
    private $id;

    /**
     * @var int
     *
     * we need this since the tag index only works with integers
     *
     * @ORM\Column(type="integer")
     */
    private $tagId;

    /**
     * @param int $tagId
     *   …
     */
    public function __construct(
        $tagId
        
    ) {

Creating new instance of entity

        $myEntity = new MyEntity(
            $this->myEntityRepository->getNextTagId(),

        );

Repository

    public function getNextTagId(): int
    {
        return (int) $this->getEntityManager()->createQueryBuilder()
            ->select('(COALESCE(MAX(e.tagId), 0) + 1) AS tagId')
            ->from(MyEntity::class, 'e')
            ->getQuery()
            ->getSingleScalarResult();
    }

@carakas carakas closed this Aug 2, 2017

@carakas carakas reopened this Aug 2, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment