Giter Site home page Giter Site logo

Comments (6)

fadoe avatar fadoe commented on August 23, 2024 2

@pmjones I played around and Atlas is a very good ORM. Not so bloated like doctrine. Thank you for this great work!
I think you should not remove the strict validation. Programs should validate the input/output.

Thanks again. I close this question.

from atlas.orm.

sunkan avatar sunkan commented on August 23, 2024 1

Hi

Have you had a look at https://github.com/atlasphp/Atlas.Orm/blob/2.x/docs/events.md

You could use the table events to turn the data to binary before update/Insert and then on select turn them back into string

from atlas.orm.

pmjones avatar pmjones commented on August 23, 2024

@fadoe does @sunkan's answer help you out?

from atlas.orm.

fadoe avatar fadoe commented on August 23, 2024

I test it with

class StationTableEvents extends TableEvents
{
    public function modifySelectedRow(TableInterface $table, RowInterface $row): void
    {
        $id = $row->id;

        $value = $this->convertToPHPValue($id);
        $row->id = $value;
    }

    private function convertToPHPValue($value): ?StationId
    {
        return $value ? StationId::fromString(Uuid::fromBytes($value)->toString()) : null;
    }

    private function convertToDatabaseValue($value): ?string
    {
        return $value instanceof StationId ? Uuid::fromString((string) $value)->getBytes() : null;
    }
}

But now i get this exception trace:

Exception trace:
 Atlas\Orm\Exception::invalidType() at /home/falk/Projekte/Applications/playlistgrabber/vendor/atlas/orm/src/Table/Row.php:323
 Atlas\Orm\Table\Row->assertValid() at /home/falk/Projekte/Applications/playlistgrabber/vendor/atlas/orm/src/Table/Row.php:297
 Atlas\Orm\Table\Row->modify() at /home/falk/Projekte/Applications/playlistgrabber/vendor/atlas/orm/src/Table/Row.php:122
 Atlas\Orm\Table\Row->__set() at /home/falk/Projekte/Applications/playlistgrabber/src/PlaylistGrabber/src/Infrastructure/Persistence/AtlasOrm/Station/StationTableEvents.php:25
 FaDoe\PlaylistGrabber\Infrastructure\Persistence\AtlasOrm\Station\StationTableEvents->modifySelectedRow() at /home/falk/Projekte/Applications/playlistgrabber/vendor/atlas/orm/src/Table/AbstractTable.php:544
 Atlas\Orm\Table\AbstractTable->getSelectedRow() at /home/falk/Projekte/Applications/playlistgrabber/vendor/atlas/orm/src/Table/TableSelect.php:330
 Atlas\Orm\Table\TableSelect->fetchRows() at n/a:n/a
 call_user_func_array() at /home/falk/Projekte/Applications/playlistgrabber/vendor/atlas/orm/src/Mapper/MapperSelect.php:127
 Atlas\Orm\Mapper\MapperSelect->__call() at /home/falk/Projekte/Applications/playlistgrabber/vendor/atlas/orm/src/Mapper/MapperSelect.php:263
 Atlas\Orm\Mapper\MapperSelect->fetchRecords() at /home/falk/Projekte/Applications/playlistgrabber/src/PlaylistGrabber/src/Infrastructure/Station/Repository/AtlasOrmStationRepository.php:42
...

So I think the best place to do this cast is in the repository after fetching the data. Or to write a entity that can handle the binary version for the ORM and the ValueObject version for the application.

from atlas.orm.

pmjones avatar pmjones commented on August 23, 2024

@fadoe Ah so! Yes, casting at the Domain level is probably the right thing to do in this case; I did not realize that you were trying to store an object in the Row.

FWIW, remember that Atlas is intended to model the persistence layer, not the domain layer. With that design constraint in mind, I wrote the Row::assertValidValue() method to make sure that only scalars and nulls could be set as values on a row, since scalars and nulls are the only things that move back and forth between PHP and the database. As such, the "right" place to create objects from Row values is in the domain layer.

However, I have lately begun to think that validation approach is a little too restrictive; in a future version of Atlas I expect to relax or remove it. Relaxing it in 2.x might be possible without breaking BC (and expectations) but I am not sure at this point.

Sorry for the hassle, and let me know if we can close this issue for now.

from atlas.orm.

pmjones avatar pmjones commented on August 23, 2024

Thanks for saying so @fadoe :-)

from atlas.orm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.