Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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 search to work with uuids #1962

Closed
carakas opened this issue Jan 28, 2017 · 1 comment
Closed

Allow the search to work with uuids #1962

carakas opened this issue Jan 28, 2017 · 1 comment

Comments

@carakas
Copy link
Member

carakas commented Jan 28, 2017

Type

  • Enhancement

Problem description

You can now only use integers as id's for the search, 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 search 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
BackendSearchModel::saveIndex(string $module, int $otherId, array $fields, string $language = null)
@carakas
Copy link
Member Author

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 search index only works with integers
     *
     * @ORM\Column(type="integer")
     */
    private $searchId;

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

Creating new instance of entity

        $myEntity = new MyEntity(
            $this->myEntityRepository->getNextSearchId(),
            …
        );

Repository

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

@carakas carakas removed this from the 6.0.0 milestone Mar 17, 2021
@carakas carakas closed this as completed Mar 17, 2021
@forkcms forkcms locked and limited conversation to collaborators Mar 17, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests

2 participants