Yii Framework Forum: Active Records in 2.0 - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Active Records in 2.0

#1 User is offline   iScotts 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 20
  • Joined: 31-January 12

Posted 06 April 2012 - 06:28 AM

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?
1

#2 User is offline   Fesor 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 02-March 09
  • Location:Belarus, Minsk

Posted 07 April 2012 - 03:50 PM

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.
Bend Before The Ways Of Heavy Metal! © Six-String Samurai
0

#3 User is offline   robregonm 

  • Expert Yii Developer
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 591
  • Joined: 30-July 09
  • Location:Colombia

Posted 10 April 2012 - 01:56 PM

+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.
Ricardo Obregón

YiiFramework en Español - http://yiiframework.co/ - http://yiiframeworkenespanol.org/ - Yii Code Generator for Bootstrap
http://obregon.co/ - https://1server.co/
PHP 5.5+, nginx 1.4, MySQL(MariaDB & PerconaDB), PostgreSQL 9, Yii 2.0-dev.
Follow me: @robregonm & @obregonco & @1ServerCo.
0

#4 User is offline   Jaggi 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 90
  • Joined: 05-September 11

Posted 11 April 2012 - 03:07 AM

doesn't migrations cover this?
See my development site @ www.CodeTheInter.net (BETA)

Posted Image Posted Image

Quote

If you make it idiot proof, they'll build a better idiot
0

#5 User is offline   ololo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 37
  • Joined: 23-January 11
  • Location:Minsk, Belarus

Posted 11 April 2012 - 05:20 AM

@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)
1

#6 User is offline   mauricioschneider 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 152
  • Joined: 16-August 10
  • Location:Santiago, Chile

Posted 11 April 2012 - 02:26 PM

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

#7 User is offline   Ivica 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 311
  • Joined: 25-May 11

Posted 11 April 2012 - 11:04 PM

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.
Zurmo: Yii Powered Open Source CRM
zurmo.org
0

#8 User is offline   iScotts 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 20
  • Joined: 31-January 12

Posted 13 April 2012 - 04:26 PM

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..
0

#9 User is offline   Da:Sourcerer 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,162
  • Joined: 30-March 11
  • Location:Berlin, Germany

Posted 14 April 2012 - 03:27 AM

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?
programmer /ˈprəʊgramə/, noun: a device that converts ►coffee into ►code
0

#10 User is offline   Diegovl 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 96
  • Joined: 27-February 11

Posted 14 April 2012 - 08:50 AM

I got to try Doctrine, and with him the use of Fixtures and schema yml format. One of the most useful things I ever had for my hands.
0

#11 User is offline   erkasoft 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 24-December 11
  • Location:turkey

Posted 14 April 2012 - 10:21 AM

View PostiScotts, on 06 April 2012 - 06:28 AM, said:

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.

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.
Ertan Kayalar
PHP, Yii, Wordpress, MySQL
http://www.erkasoft.com
Followme: @erkasoft, @24saat
0

#12 User is offline   knut 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 45
  • Joined: 10-October 08
  • Location:Notodden, NORWAY

Posted 16 April 2012 - 03:16 AM

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).
1

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users