Gas ORM |
[eluser]toopay[/eluser]
A lighweight and easy-to-use ORM for CodeIgniter. Gas was built specifically for CodeIgniter app. It uses standard CI DB packages, also take anvantages of its validator class. Gas provide methods that will map your database table and its relation, into accesible object. [h4]For download or recent update, look at GasORM @ GitHub. This library also available at Sparks. For guide and example go to Documentation for version 1.x.x.[/h4] [h3]Requirements[/h3] 1. PHP v.5.2.x 2. CodeIgniter v.2.x.x [h3]Features[/h3] 1. Supported databases : cubrid, mssql, mysql, oci8, odbc, postgre, sqlite, sqlsrv. 2. Support multiple database connection. 3. Support modular models directories and sub-models directories. 4. Multiple relationship (has_one, has_many, belongs_to, has_and_belongs_to) with custom relationship setting (through, foreign_key, foreign_table, self). 5. Auto-create models from database tables and vice versa, and auto-synchronize models-tables by creating migrations file. 6 Per-request caching. 7. Self-referential and adjacency column/data (hierarchical data). 8. Eager Loading. 9. Various finder method (can chained with most of CI AR syntax) and aggregates. 10. Validation and auto-mapping input collection, with minimal setup. 11. Hooks points, to control over your model. 12. Extensions, to share your common function/library/helper/plugin across your model instances. 13. Transaction and other CI AR goodness. 14. Command Line Interface. [h3]Planned Features[/h3] 1. Support for tree traversal data. More useful features. NOTE : latest version is v.1.4.3 (also compatible with the latest CI 2.1.0), if you using < v.1.3.0, please update. Also note that Auto-create models from tables and vice versa require CI v.2.1.x
[eluser]sqwk[/eluser]
Just discovered Gas and figured out how to use it within a couple of minutes. Great job. One thing though? Is there a way to select what fields are being selected from the DB? Code: $buyers = Gas::factory('users')->with('emails')->all() Can I tell Gas that I only want the 'id' and 'username' fields from the users table and the 'id' and 'email' field from the emails table? I found out that I can add ->select() to tell Gas what to get from the users table, but what about the email table? Also, can I eager load multiple levels? For example if there is another m:m relationship after emails?
[eluser]toopay[/eluser]
[quote author="sqwk" date="1326916072"] Can I tell Gas that I only want the 'id' and 'username' fields from the users table and the 'id' and 'email' field from the emails table? I found out that I can add ->select() to tell Gas what to get from the users table, but what about the email table? [/quote] This is what added on in the latest version. You could have something like : Code: function _init() [quote author="sqwk" date="1326916072"] Also, can I eager load multiple levels? For example if there is another m:m relationship after emails?[/quote] In latest version, sure. You could have something like : Code: // Relationship statement block....
[eluser]sqwk[/eluser]
[quote author="toopay" date="1326949314"] Code: // Relationship statement block.... Not entirely sure about the syntax here. Could you explain what all the \\, => and <= are doing?
[eluser]toopay[/eluser]
'\\' is used, because all gas model should have namespace, and in string variable we cannot write '\'. And '=>' or '<=' is to simplify our relationship paths. The relationship interpreter, will parsing and break down above path into paired tuples as follow : Code: //'=>' mean LEFT is belongs to RIGHT Code: $user = Model\User::find(1); Code: $user1 = Gas::factory('user')->find(1);
[eluser]sqwk[/eluser]
Is it just me or is that a completely different syntax to what is listed in the wiki?
[eluser]toopay[/eluser]
Its for 2.0, and i did not update the wiki yet. Version 1.X.X syntax will remain, as is. There are several things left, to completely release this new version. I just answer your previous question, regarding possibility to achive those task, within this new version.
[eluser]brunobarros[/eluser]
@toopay I'm trying to implement Gas on my already born system. I do something similar to Wordpress. I have a table "content" with posts, categories etc. =========== content =========== id title category_id =========== If the line is a category the category_id is '0', otherwise it is the ID of a category. In this case, do I need one single Model? I tried both, mapping with one and two models, one to posts and another to categories... but I could not get the category title. Ex: $content->title Ex: $content->category->title Is it possible? Tnks
[eluser]toopay[/eluser]
@brunobarros, You could use self-referential option if you go with one table.
[eluser]brunobarros[/eluser]
Yeah man, I did it and works. See... Code: Content_gas And I called the GAS: Code: $posts = Gas::factory('content')->where(array('category_id !=' => 0))->with('content')->all(); Inside de loop: Code: foreach ($posts as $post) { Is there a way to do it better? If a could reference the category using: $post->category->title would be much better, don't you think? |
Welcome Guest, Not a member yet? Register Sign In |