Comments (6)
@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.
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.
@fadoe does @sunkan's answer help you out?
from atlas.orm.
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.
@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.
Thanks for saying so @fadoe :-)
from atlas.orm.
Related Issues (20)
- Cached Queries HOT 8
- The name of the static method 'new' in the Atlas class seems to generate a parse error in third party libraries like phpDocumentor HOT 14
- joinWith doesn't work when specifying direction
- On updates, 1 and true and not being treated as the same for bit/boolean columns and values HOT 1
- Cannot delete all records in a many-to-many HOT 4
- Wrong parameters for PDOException? HOT 1
- Updating Many to Many?
- Postgres: problem when using uuid type field HOT 3
- Question: how to use raw insert values in ORM HOT 3
- Support for read-only MySQL generated columns
- Help: how to use advanced ORM feature HOT 5
- Help: Only the first result in a select includes data from related records HOT 7
- [Help Required] Getting Atlas\Mapper\Exception when trying to fetch a record from SQLite HOT 3
- How to use PHP-DI PSR 11 and Repository HOT 1
- Does Atlas.Orm suffer of the problem of useless order by on some ORM prefetches ?
- Row name for Exception::rowNotMapped() and Exception::rowAlreadyMapped() HOT 1
- orderBy missing HOT 1
- Issue with character encoding HOT 12
- Relationships manyToOne NULL HOT 8
- Missing get PDO connection from Atlas ORM HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from atlas.orm.