nextras / orm

Orm with clean object design, smart relationship loading and powerful collections.
https://nextras.org/orm
MIT License
309 stars 59 forks source link

Embeddable as part of composite primary key #682

Open MartinLojda opened 1 month ago

MartinLojda commented 1 month ago

First attemp of fixing issue #575

hrach commented 1 month ago

We need tests, I can add them but please, send me a real usecase :) What's your usage?

MartinLojda commented 1 month ago

I have composite primary key that consist of relation (that works fine) and DataRangeEmbeddable which is containing two DateTimeImmutables.

Entity is like this:

 * @property array $id {primary-proxy}
 *
 * @property Trailer $trailer {m:1 Trailer, oneSided=true} {primary}
 * @property DateRangeEmbeddable $date {embeddable} {primary}
 *

And DateRangeEmbeddable is like this:

/**
 * @property DateTimeImmutable $from
 * @property DateTimeImmutable $to
 */

I need to work with date ranges a lot, so it makes sense for me to store it in a special object (for type safety, constraints checks, …).

Thank you!

hrach commented 1 month ago

Ok, that's an important detail: the whole embeddable is part of the PK. Thx :)

hrach commented 3 weeks ago

@MartinLojda Could you please provide an example of how you (how do you want to) query such rows during getById() method?

MartinLojda commented 3 weeks ago

I'm thinking about property->subproperty notation to be consistent with findBy conditions… Another posibility is array of subproperties, which might be more practical for my usecase, but i'm not really convinced it is a good way how to do it. Thank you!