Bug regarding propel and entitymapping

USX5CJLS1
USX5CJLS1 Posts: 16 πŸ§‘πŸ»β€πŸš€ - Cadet
edited June 2023 in Propel ORM

Hi, i think i found an interesting bug regarding propel and entitymapping wich can cause that data is not saved. Has someone time so i can explain this issue, so that it can be addressed?

Tagged:

Best Answer

Answers

  • TheNittyGritty
    TheNittyGritty Sprykee Posts: 25 πŸ§‘πŸ»β€πŸš€ - Cadet

    Hello @USX5CJLS1,
    Could you please open a support ticket with us and we will get back to you
    http://support.spryker.com/

  • UKEP86J66
    UKEP86J66 Posts: 208 πŸ§‘πŸ»β€πŸš€ - Cadet

    If it is related to the sync:data command there is a fix in the next major release for propel entity mapping.

  • USX5CJLS1
    USX5CJLS1 Posts: 16 πŸ§‘πŸ»β€πŸš€ - Cadet

    No something else, i will write it here:

  • USX5CJLS1
    USX5CJLS1 Posts: 16 πŸ§‘πŸ»β€πŸš€ - Cadet

    i also created a supportticket for this, but fyi : i am not sure if this is fixed in the latest versions, i checked the latest implementations in the affected classes and i do not think so.

    • In propel xml-schema xml-files you can use "defaultValue"-attribute for column-tags
    • this results for persistence-baseclasses (the ones implementing \Propel\Runtime\ActiveRecord\ActiveRecordInterface) that the constructor calls applyDefaultValues()-Method with the defined defaultvalues
    • for example we have a table with one integer column called "columnA" with a xml-definition like this: ""
    • if you built a a EnityManager-class for the table with this column extending \Spryker\Zed\Kernel\Persistence\AbstractEntityManager and use save-Method, this calls \Spryker\Zed\Kernel\Persistence\EntityManager\TransferToEntityMapper::mapEntityCollection and this calls \Spryker\Zed\Kernel\Persistence\EntityManager\TransferToEntityMapper::mapEntityΒ 
    • \Spryker\Zed\Kernel\Persistence\EntityManager\TransferToEntityMapper::mapEntity uses fromArray() to map the data into EntityTransfer-Object, if there is a defaultValue defined and you want to save this default-value the column is not marked as "modifiedProperty" and therefore it is NOT added into the database INPUT-Statmenent , so if you want to save values, defined as dafaultValue this values are not saved

    Actual Behaviour: For Example:

    • Table with a column defined as Β 
    • i persist value "2" into this database column
    • i persist value "0" int this database column, this does not work, the value remains 2

    Expected Behaviour: For Example:

    • Table with a column defined as Β 
    • i persist value "2" into this database column
    • i persist value "0" int this database column, this works, the value 0 i saved to the databasecolumn

    To Reproduce: For Example:

    • Table with a column defined as Β 
    • i persist value "2" into this database column
    • i persist value "0" int this database column, this does not work, the value remains 2
  • TheNittyGritty
    TheNittyGritty Sprykee Posts: 25 πŸ§‘πŸ»β€πŸš€ - Cadet

    thx - received that one

  • USX5CJLS1
    USX5CJLS1 Posts: 16 πŸ§‘πŸ»β€πŸš€ - Cadet

    any news on this? i didnt get an issue number

  • Valerii Trots
    Valerii Trots SRE @ Spryker Sprykee Posts: 1,654 ✨ - Novice

    Not yet unfortunately. Clarifying with our development as I can't reproduce the problem. But I'm not a developer unfortunately, so I'm waiting for their feedback.

  • U013M1LC46A
    U013M1LC46A Posts: 23 πŸ§‘πŸ»β€πŸš€ - Cadet

    I’ve noticed this issue yesterday and was just about to create a bug ticket before noticing it reported here. @USX5CJLS1 your example might not be completely correct. The issue occurs when attempting to update an existing entity that has fields with a default value. Inserting a new entity works.

  • Valerii Trots
    Valerii Trots SRE @ Spryker Sprykee Posts: 1,654 ✨ - Novice

    The fix is almost or is ready to be released.

  • Valerii Trots
    Valerii Trots SRE @ Spryker Sprykee Posts: 1,654 ✨ - Novice
    Answer βœ“
  • USX5CJLS1
    USX5CJLS1 Posts: 16 πŸ§‘πŸ»β€πŸš€ - Cadet

    Thank you, we will add it into our project :-)