Eloquent like ORM for Yii

Those who are aware of Laravel framework definitely know what the beast is Eloquent and how much elegant it is.

Any plans to modify Yii ORM to be more Eloquent like? I’m planning even to implement Eloquent on core level for Yii 1.1.x but I think PHP >= 5.1 limitation will make it impossible. Eloquent is one of the best ORMs in the market, it 's compared with Doctrine but is very lightweight.

I’ve come to yii from codeigniter, and I really want to stay with it as our team developed home-made CMS based on Yii for our clients (web studio). But I want the framework to move forward and stay up to date. Our team is ready to help with the development of Yii 2.0 as soon as the alpha will go public. We’re ready to help with implementation of Eloquent ORM too on pre-alpha stages.

I’m interested what others think about Eloquent ORM and do you agree that it will be beneficial for Yii to go with it.

Link for Eloquent: http://laravel.com/docs/database/eloquent

1 Like

Have you seen Qiangs post about AR in yii 2.0 ?

I think it is quite similar to what you suggested…

If not, please point out differences :slight_smile:

I’ve reviewed it about 2 months ago. That’s what I’ve found out:

Good parts

  • Dirty attributes concept. We’ll have it in Yii2.

  • Interesting way of defining relations.

  • AR supports saving related records. Since there are dirty attributes, implementation is relatively straightforward.

Bad parts

  • Metadata isn’t selected with records and is not used at all. Models are schemaless so you can write any property and will get SQL error only when saving it.

  • There’s mass assignment but they did the same mistake RoR did allowing all by default and even more by not restricting column names.

Are there more things I’ve missed?

I think you need to be a lot more specific about the actual features and syntax you find to be so important.

I started looking at the documentation, and the first thing I noticed was that magical static properties like $table and $timestamps are used instead of a concrete API. Definitely not something I would endorse.

I don’t personally have time to try out yet another ORM. Just from a glance, I’m sure as with any ORM, some people are going to love it, and others are going to hate it.

(If you happen to have found your personal favorite, maybe you can just take the ORM and use it in Yii?)

Since Eloquent can be used with core PHP, can’t we use it with Yii, which is a PHP framework? Has anyone tried this PHP Eloquent integration method on Yii?

Hi Friends,

What I like about Eloquent is the use of with, the way it return datas


Response :-
id: 1,
fname: Paul,
mob: 0788667756,
order: {
id: 2,
user_id: 1,
qty: 5,
price: 2600.00
id: 2,
fname: John,
mob: 0715001111,
order: {
id: 20,
user_id: 2,
qty: 7,
price: 600.00

In Yii how can do it in simple way to have the same result


Assuming you are familiar with ActiveQuery and how you can extend it to add your own functionality the answer is kinda yes.

See this project GitHub - thecodeholic/Yii2-Youtube-Clone: Youtube clone made with Yii2 framework under common\models as an example of how you can go about it.


1 Like