-
-
Notifications
You must be signed in to change notification settings - Fork 507
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 increment strategy for not defined types #1815
Conversation
As decimal128 is not provided by doctrine types, it may be created as custom type. But even if mongo allows to use increment strategy with decimal128, doctrine throws an exception, that increment storage strategy is not allowed. Only doctrine restriction is to deal with. No other implementation is needed.
Yes and no - we should rather ship the new type by default, allowing users to use it without implementing custom types. This would also allow us to not allow the increment strategy for all types by default but rather allow it for the new decimal128 type. Would you be up for adding the decimal128 type to ODM 2.0? |
@alcaeus I'm not that confident to do that. Just started to work with mongo. But I can't get the idea of not existing of customized storage types and therefore having such restriction. |
Note that in order to increment a Decimal128 object one will need to convert it to a string, calculate the increment (likely using The driver's handling of Decimal128 is currently limited to conversion to/from a string. It does not implement the necessary On a related note, Internal operator overloading and GMP improvements was implemented in PHP 5.6 (php/php-src#342). GMP only supports integer math. The RFC did allude to supporting BCMath but I don't think that was ever implemented. That is likely because the The relevant code for actually handling the "increment" storage strategy is in PersistenceBuilder: mongodb-odm/lib/Doctrine/ODM/MongoDB/Persisters/PersistenceBuilder.php Lines 149 to 151 in e7c926b
@uLow: That will require some modifications to actually support the feature you're asking for. Simply adding Thinking more generally, the best way to implement this may be to allow types (either custom or ODM's built-in types) to implement some interface that provides a method to calculate an increment.This would basically be a limited form of operator overloading used expressly for ODM's increment strategy. If implemented, a future Decimal128 type in ODM could then implement this interface and utilize BCMath internally as it wishes. @alcaeus: If that seems reasonable, perhaps you can quote/paraphrase this comment and create an issue to track the feature request for a future ODM version.
|
Given the excellent explanation by @jmikola, I'm closing this one here. Just allowing the I've created #1835 to track the feature request to add a new |
Summary
As decimal128 is not provided by doctrine types, it may be created as custom type. But even if mongo allows to use increment strategy with decimal128, doctrine throws an exception, that increment storage strategy is not allowed. Only doctrine restriction is to deal with. No other implementation is needed.