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
Can we map columns to class properties? #280
Labels
Comments
Yes, you can use Plain PHP objects for that. Here is a simple example: // MovieMap.php
namespace App\Maps;
use Analogue\ORM\EntityMap;
class MovieMap extends EntityMap
{
protected $properties = [
'id',
'title',
];
}
// Movie.php
namespace App\Entity;
class Movie
{
/**
* @var int
*/
protected $id;
/**
* @var string
*/
protected $title;
...
// Getters and Setters and other business logic
}
// register entity normally
use App\Entity\Movie;
use App\Map\MovieMap;
$analogue->register(Movie::class, MovieMap::class); |
That's way cleaner than Eloquent 😮 , thanks! |
What about properties with different names from DB columns? |
I haven't test this scenario (plain PHP object and mapped DB columns), but I think It can work if you map DB columns to properties like this: // MovieMap.php
namespace App\Maps;
use Analogue\ORM\EntityMap;
class MovieMap extends EntityMap
{
protected $properties = [
'ID',
'Title_Of_Movie',
];
protected $mappings = [
'ID' => 'id',
'Title_Of_Movie' => 'title',
];
}
// Movie.php
namespace App\Entity;
class Movie
{
/**
* @var int
*/
protected $id;
/**
* @var string
*/
protected $title;
...
// Getters and Setters and other business logic
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I would like to know if it is possible to map columns to class properties, most because of type checking that Eloquent ridiculously can’t do in a no magical way.
The text was updated successfully, but these errors were encountered: