Skip to content

Conversation

@greg0ire
Copy link
Member

Right now, the ORM handles the conversion of strings that happen to be default expressions for date, time and datetime columns into the corresponding value objects.

Let us allow users to specify these value objects directly, and deprecate relying on the aforementioned conversion.

@greg0ire
Copy link
Member Author

greg0ire commented Nov 19, 2025

TODO:

  • figure out how to address the deprecation when using XML mapping
  • update docs

@greg0ire greg0ire force-pushed the deprecate-conversion branch 3 times, most recently from 07875f4 to 73a95a8 Compare November 20, 2025 22:56
@greg0ire greg0ire marked this pull request as ready for review November 20, 2025 23:03
@greg0ire greg0ire force-pushed the deprecate-conversion branch from 17a68cb to 5630107 Compare November 21, 2025 07:54
@greg0ire greg0ire force-pushed the deprecate-conversion branch 10 times, most recently from 3cb990e to 11bd618 Compare November 22, 2025 09:53
Comment on lines 684 to 685
if ($nameAttribute === 'default' && is_string($value) && is_a($value, DefaultExpression::class, true)) {
$array['default'] = new $value();
Copy link
Member

@morozov morozov Nov 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how widely the XML driver is used and how maintainable it needs to be, but this is a bit hacky. If the default value of a string field matches an expression class, the driver will generate an expression, which will be invalid. Effectively, this is the same magic that the deprecation in the DBAL attempts to eliminate.

I don't have a problem if it's done the way it's done now. Properly accommodating a new type requires a change in the XML schema (for example, like PHPUnit used to do).

Copy link
Member Author

@greg0ire greg0ire Nov 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, it's not great… I'll have to think more about this. I'm thinking that it might not make sense to allow having children tags for all option tags. So maybe options should allow both option and default-expression as a child? But then it creates the possibility to have default-expression alongside option name="default" 😬

Maybe the best would be option name="default" class="Doctrine\DBAL\Schema\DefaultExpression\CurrentTimestamp", I'm really not sure about this.

This comment was marked as resolved.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@morozov I've implemented support for <object>.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. This looks much better.

@greg0ire greg0ire force-pushed the deprecate-conversion branch from 11bd618 to 9ccca55 Compare December 7, 2025 19:03
<xs:complexType name="option" mixed="true">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="option" type="orm:option"/>
<xs:element name="object" type="orm:object"/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is the right place to put the new element. Currently, I can provide multiple <object> elements for a single <option>, and the document will still be valid.

            <options>
                <option name="default">
                    <object class="Doctrine\DBAL\Schema\DefaultExpression\CurrentDate"/>
                    <object class="Doctrine\DBAL\Schema\DefaultExpression\CurrentTime"/>
                </option>
            </options>

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know much about XSD, but my LLM does so I had it prevent this possibility. It's implemented as a choice of 1 element between <object>, and an unbounded sequence of what was previously under the existing xs:choice.

Right now, the ORM handles the conversion of strings that happen to be
default expressions for date, time and datetime columns into the
corresponding value objects.

Let us allow users to specify these value objects directly, and
deprecate relying on the aforementioned conversion.
@greg0ire greg0ire force-pushed the deprecate-conversion branch from 9ccca55 to f312fcb Compare December 7, 2025 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants