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

🔑 UUID as primary key #565

Open
radimvaculik opened this issue Mar 2, 2022 · 5 comments
Open

🔑 UUID as primary key #565

radimvaculik opened this issue Mar 2, 2022 · 5 comments
Labels

Comments

@radimvaculik
Copy link
Contributor

Example into docs, how to easily setup UUID as primary key.

@mabar
Copy link
Contributor

mabar commented Mar 2, 2022

DB column
"id" uuid PRIMARY KEY,

Assign (read-only) id in entity constructor

/**
 * @property-read string $id {primary}
 */
class Foo extends Entity
{
	public function __construct()
	{
		parent::__construct();
		$this->setReadOnlyValue('id', (new \Symfony\Component\Uid\Ulid())->toRfc4122());
	}
}

That should be basically it.

@radimvaculik
Copy link
Contributor Author

@mabar uuid data type was added in MariaDB 10.7. No data type support for MySQL (https://dev.mysql.com/blog-archive/mysql-8-0-uuid-support).

@hrach
Copy link
Member

hrach commented Mar 2, 2022

I've never used UUID so I'm puzzled a little. What is the issue? From ORM pov there are two things:

  • mapping -> string to some type in DB -> this should be either ok or covered by doc
  • setting the id programatically -> Mabar's example is quite ok

So what do you miss?

@hrach hrach added doc and removed feature labels Mar 2, 2022
@mabar
Copy link
Contributor

mabar commented Mar 2, 2022

My example is for PostgreSQL. In MySQL char(36) should work just as fine, just way less performant.

I tried to use UUID with binary in MySQL and performance was almost like with native UUID, but IDs in queries became just unreadable. In Nextras ORM it can be done by setting mapping callbacks in DbalMapper, but be aware mapping of IDs is not fully supported - described in #291


So current limitation is IDs cannot be mapped to binary for database storage and cannot be mapped to a value object in php.

@hrach
Copy link
Member

hrach commented Mar 2, 2022

Hm, that would be good reason to proceed with 291.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants