-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Implement native ORM #289
Comments
Thanks for your interest! At this time, we don't plan on including an ORM, but are looking into ways to make it simpler to integrate with third-party ORMs. However, most third-party ORMs can be used within any CodeIgniter application already. Use Composer to load it. Ensure the |
excellent thanks for your reply |
I found simple ORM for CodeIgniter 3. https://github.com/yidas/codeigniter-model/blob/master/README.md I think this can be used as CI4 default Model or added as optional model library. Thanks. |
You can implement the Eloquent ORM easily, I think it is currently the simplest and best option. |
I first read that as it would be a simple thing for us to build in the framework and starting laughing. I know that Taylor has said the most difficult thing he did with the framework was the ORM.
Well... our model already handles 80%+ of that. Some of that belongs at the framework level and not the model level, and it doesn't support any form of relationship management, which is what most people want from an ORM. But if you like it - help them modify it to work in CI4 and use it your projects. |
A quick question @lonnieezell about how load a new service like ORM on CI4, for example Eloquent: composer.json
application/Services/DatabaseService.php <?php
namespace App\Services;
use Illuminate\Database\Capsule\Manager;
class DatabaseService {
public function __construct() {
$manager = new Manager();
$manager->addConnection([
"driver" => 'mysql',
"host" => getenv('database.default.hostname'),
"database" => getenv('database.default.database'),
"username" => getenv('database.default.username'),
"password" => getenv('database.default.password'),
]);
$manager->bootEloquent();
}
} application/Models/User.php <?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class User extends Model {
protected $fillable = ['name', 'email', 'password'];
public function scopeRandom () {
return $this->orderByRaw("RAND()")->first();
}
public function getNameAndEmailAttribute () {
return sprintf('Nombre: %s, Email: %s', $this->name, $this->email);
}
} This is a full implementation, but, which is the best way for load a service like it? Thanks for your help! |
@uno-de-piera I would just create a new method in |
Thanks @lonnieezell, great job. |
It would be an excellent decision native implementation of an ORM own, or take an existing one and integrate, to give more tools to developers.
The text was updated successfully, but these errors were encountered: