Active Records in 2.0

I Really like the current ORM yii has. But wouldnt it be nice is we had an ORM where we didnt even have to design our own Database? Something like RedBeans, which automatically creates your tables for you.

Im not sure if this is how redbean does this, but I imagine a ORM where you just design you classes ike you would in OOP.

you set your attributes and from there the orm will design the database for you, this way even inheritance and stuff would be easier for the developer. Now I know not all attributes are variable maybe there could be a way for us to differentiate the two for the ORM to design the correct models with correct columns in the database. This could remove the sometimes irritating task of having to decide what DB data type to use, the ORM could just set this for us, unless explicitly stated otherwise.

Do you guys think this is a good idea… Yes? no? maybe?

It is possible to create commands for create/update schema.

You also may look at the Doctrine 2. I think it’s pretty match to your requests.

+1 Totally agree.

I can find it in Rails, django and some other frameworks…

It would be great to have this key feature in Yii.

doesn’t migrations cover this?

@iScotts there is Doctrine2 ORM and it does everything you want

this ORM is a really great project and it’s worth to design Yii2 so that it could be integrated with Doctrine2 with no pain, probably in form of adapter extension turning Doctrine2 into YII-like ActiveRecord (see this) so we can work with AR and still use such things as inheritance mapping and doctrine migrations like in sf2 DoctrineMigrationsBundle with its’ diff which allows to keep sources and DB exactly corresponding each other (unlike Gii and its’ revers engineering). I mean with Gii you sometimes have to change generated code or redeclare it in children classes (like in giix)

Loves how it sounds ololo, this was one of the few features I missed when switching from sf to yii.

We implemented Active Record based on RedBeanPHP ORM which completely replace Yii Active record, and it works very good so far. You can check Zurmo source code, and see what we did.

It is good when you don’t have to take care about your database. Right now I am using database only when developing some new feature, just to check if everything is fine. There are many unit tests that we are wrote to check if our RedBeanModel elements works fine.

ReadBean database can be into two stages: frozen and unfrozen. In unfrozen stage it is possible to change db structure, and it is much slower. It is usually used in development phase of project. Once you finished development phase you need to switch it into frozen stage. Off course during schema update, it must be in unfrozen state.

You don’t have to worry about migrations files. For every model we define its structure, types, elements, relations, and then we just run updateSchema command, and db is updated automatically.

Ok I had a look at Doctrine and It looks like it is the complete package… but I am really a fan of out of the box and integrated features. That way you know for sure that the feature is maintained and it wont clash with other extensions or need any altering… But for now I guess i would be a good alternative…

I’m just wondering all the time … couldn’t you implement this as a behavior? Preferably as one that will only sync the schema while the application is in dev-mode?

[color="#333333"][font="arial, sans-serif"][size="2"]I[/size][/font][/color][color="#333333"][font="arial, sans-serif"] [/font][/color][color="#333333"][font="arial, sans-serif"][size="2"]got to try[/size][/font][/color][color="#333333"][font="arial, sans-serif"] [/font][/color][color="#333333"][font="arial, sans-serif"][size="2"]Doctrine,[/size][/font][/color][color="#333333"][font="arial, sans-serif"] [/font][/color][color="#333333"][font="arial, sans-serif"][size="2"]and[/size][/font][/color][color="#333333"][font="arial, sans-serif"] [/font][/color][color="#333333"][font="arial, sans-serif"][size="2"]with him[/size][/font][/color][color="#333333"][font="arial, sans-serif"] [/font][/color][color="#333333"][font="arial, sans-serif"][size="2"]the use[/size][/font][/color][color="#333333"][font="arial, sans-serif"] [/font][/color][color="#333333"][font="arial, sans-serif"][size="2"]of[/size][/font][/color][color="#333333"][font="arial, sans-serif"] [/font][/color][color="#333333"][font="arial, sans-serif"][size="2"]Fixtures[/size][/font][/color][color="#333333"][font="arial, sans-serif"] [/font][/color][color="#333333"][font="arial, sans-serif"][size="2"]and schema[/size][/font][/color][color="#333333"][font="arial, sans-serif"] [/font][/color][color="#333333"][font="arial, sans-serif"][size="2"]yml[/size][/font][/color][color="#333333"][font="arial, sans-serif"] [/font][/color][color="#333333"][font="arial, sans-serif"][size="2"]format[/size][/font][/color][color="#333333"][font="arial, sans-serif"][size="2"].[/size][/font][/color][color="#333333"][font="arial, sans-serif"] [/font][/color][color="#333333"][font="arial, sans-serif"][size="2"]One of the[/size][/font][/color][color="#333333"][font="arial, sans-serif"] [/font][/color][color="#333333"][font="arial, sans-serif"][size="2"]most useful things[/size][/font][/color][color="#333333"][font="arial, sans-serif"] [/font][/color][color="#333333"][font="arial, sans-serif"][size="2"]I ever had[/size][/font][/color][color="#333333"][font="arial, sans-serif"] [/font][/color][color="#333333"][font="arial, sans-serif"][size="2"]for my[/size][/font][/color][color="#333333"][font="arial, sans-serif"] [/font][/color][color="#333333"][font="arial, sans-serif"][size="2"]hands[/size][/font][/color][color="#333333"][font="arial, sans-serif"][size="2"].[/size][/font][/color]

I agree with you. I have used Doctrine1 & Redbeans PHP. Yii ORM is very well and enough for me. But Readbeans features should be good in Yii ORM2. Doctrine1 is big lib. Redbeans small and simple. I prefer Redbeans instead Doctrine1. I don’t know Doctrine2 yet. But export/import fixtures (yaml or xml) features also good choice for Yii.

From my point of view, interfaces for schemaless databases like MongoDB, CouchDB is a must in Yii 2 (I noticed it’s even mentioned in the todo-list). Redis is also really popular now. In addition to a state of the art Active Record implementation in Yii 2 I think it’s equally interesting to have libraries for NoSQL-db’s. Together with some nice tutorials I think even more web developers will jump onto those technologies.

The underlying query syntax (SQL vs. Map-Reduce is quite different though, while simple save/update/delete could be similar, not sure yet how a more complex retrieval interface would be).