EllisLab text mark
Advanced Search
1 of 19
1
   
Gas ORM
Posted: 01 November 2011 08:35 PM   [ # 11 ]   [ Rating: 0 ]
Avatar
Joined: 2010-12-20
1591 posts

Updated to v.1.0.3

Changes :
1. Add factory pattern implementation, via static function.
2. Add fill() method, to automaticly mapped $_POST data for next save() method
3. Design and performance improvement.

 

 

 Signature 

“In Code We Trust.”


CI Library : Gas ORM | Proxy

 
Posted: 03 November 2011 06:20 AM   [ # 12 ]   [ Rating: 0 ]
Avatar
Joined: 2010-12-20
1591 posts

For license compatibility reasons, i ended up change all my library license, including Gas ORM from GPL to compatible license. By latest commit, Gas ORM is now also compatibility with PHP v.5.2.x, since some issues reporting by user based by previous commit (same version) under PHP 5.2, which apparently caused by Scope Resolution Operator.

Oh btw, i’m start adding language files, so if your language isn’t there, dont hesitate to add/pull request your language on it.

 Signature 

“In Code We Trust.”


CI Library : Gas ORM | Proxy

 
Posted: 03 November 2011 06:01 PM   [ # 13 ]   [ Rating: 0 ]
Avatar
Joined: 2008-03-19
164 posts

Taufan, I can’t use has_result() to catch empty result. I’ve got an error when trying to get data that isn’t exist (should return empty value), my script is

$user Gas::factory('users_data');
$profile $user->find(2)->user_profiles

. How to solve that? Thanks

edited: p.s I use CI 2.0.3, HMVC 5.4, and Gas 1.0.3

 Signature 

AutoACL - Access Control Library++ with Very Private Page (VPP) Control
AutoCRUMB - The simplest breadcrumb helper ever
Autocrumb on bitbucket
Integrate CI 2 with Eclipse
———————————————————————————————-
Website: ardinoto.blogspot.com

 
Posted: 03 November 2011 10:56 PM   [ # 14 ]   [ Rating: 0 ]
Avatar
Joined: 2010-12-20
1591 posts

@ardinotow, In earlier version, when we try to fetch record(s) from a table using a finder with Gas ORM, either we try to fetch a set of records or just a single record which didnt exist, Gas will return an instance with empty record, so we could use ‘has_result’ method. This could be a problems, since if the records exist, find() will return an object while all() will return a set/array of object. To resolve this non uniformal behaviour, i had encourage people to use empty(), because Gas will return FALSE(for single record method) or empty array(for all(), or any finder which expect more than one records) if queries return an empty response.

So, you could do something like this instead:

$user Gas::factory('users_data')->find(2);

$profile = empty($user) ? 'User not found.' $user->user_profiles

Soon, i will remove ‘has_result’ method from Gas.

 Signature 

“In Code We Trust.”


CI Library : Gas ORM | Proxy

 
Posted: 04 November 2011 07:59 AM   [ # 15 ]   [ Rating: 0 ]
Avatar
Joined: 2008-03-19
164 posts

Thanks, it works. I think you should write full documentation and should be easy to understand just like Codeigniter’s user guide on Active Record. Sukses slalu Mas!

 Signature 

AutoACL - Access Control Library++ with Very Private Page (VPP) Control
AutoCRUMB - The simplest breadcrumb helper ever
Autocrumb on bitbucket
Integrate CI 2 with Eclipse
———————————————————————————————-
Website: ardinoto.blogspot.com

 
Posted: 05 November 2011 07:56 AM   [ # 16 ]   [ Rating: 0 ]
Avatar
Joined: 2010-12-20
1591 posts

Updated to v.1.1.0 (stable)

This stable version works with latest CI 2.1.0 branch at github.

Changes :
1. Support deep multiple relationships.
2. Support multiple database connection.
3. Support transaction.
4. Remove has_result() method, which become non-uniformal method for finder.

More about this, including example oh how to utilize Gas in your model, validate data with Gas, also some benchmarking test is on my blog post.

@ardinotow (and other who expect documentation), You can found example usage on README, and more examples in gasunittest.php(both in documentation section, and in the code itself). But for complete method and example, i started create a public gist for Gas. If you found some missed methods/examples, you can add your own implementation on those gist, so you can help everyone else who use it.

 Signature 

“In Code We Trust.”


CI Library : Gas ORM | Proxy

 
Posted: 06 November 2011 08:49 AM   [ # 17 ]   [ Rating: 0 ]
Avatar
Joined: 2008-03-19
164 posts

On the model, can we use a class name that doesn’t exist on my table? Here’s how I got problem:
1. I run gasunittest, and sort after that there were new files created on my models.
2. I changed models/wife_gas.php to wifes_gas.
3. I modified wifes_gas.php to:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class 
Wifes extends Gas {

 
public $table 'wife';
 
 public 
$relations = array(
    
'belongs_to' => array('user' => array()),
 );

 function 
_init()
 
{

 }

Notice that I added public $table = ‘wife’;
4. Create controllers/manage_user.php
I added this code:

$users Gas::factory('user')->with('wifes')->all();

  foreach(
$users as $single_user)
  
{
   var_dump
($single_user->wife);
   echo 
$single_user->name;
   
$wife_name = ($single_user->wife == FALSE) ? '' $single_user->wife->name// dipakai bila menggunakan with();
   
   
echo $wife_name;
   echo 
'<br>';
  

When I point my browser to mysite/manage_user, I got error: Model user located, but missing relationship properties.

Please help me, I’d like to use your ORM but got stuck on customizing table name. Thanks

 Signature 

AutoACL - Access Control Library++ with Very Private Page (VPP) Control
AutoCRUMB - The simplest breadcrumb helper ever
Autocrumb on bitbucket
Integrate CI 2 with Eclipse
———————————————————————————————-
Website: ardinoto.blogspot.com

 
Posted: 06 November 2011 11:17 AM   [ # 18 ]   [ Rating: 0 ]
Avatar
Joined: 2007-09-05
65 posts

Toopay does the

fill() 

method XSS filtering of the $_POST array? it would be a good feature… smile

As an alternative, we can feed the method using the Input class instead of the raw $_POST data:

$user->fill($this->input->post()); 
 Signature 

Visit my CodeIgnited webpage @ http://www.stefanogiordano.it

 
Posted: 06 November 2011 09:53 PM   [ # 19 ]   [ Rating: 0 ]
Avatar
Joined: 2010-12-20
1591 posts

@ardinotow, :
1. Make sure you download the latest version : here

2. Your user’s relationship, should refer to class name, not table name. Gas will take care your table name, primary key, relationship and other stuff automatically. So if you have wifes as your user’s one-to-one relationship, your user model should have :

public $relations = array(
    
'has_one' => array('wifes' => array()),
); 

3.Then you can create a controller contain :

$users Gas::factory('user')->with('wifes')->all();

foreach(
$users as $single_user)
{
   var_dump
($single_user->wifes);
   echo 
$single_user->name;
   
$wife_name = (empty($single_user->wifes)) ? '' $single_user->wifes->name// dipakai bila menggunakan with();
   
   
echo $wife_name;
   echo 
'<br>';

Tolong konfirmasi, kalau-kalau masih ada isu soal ini atau sudah fix, ya. smile

@stefano :
Gas would not having duplication, to cover XSS, because CI already did that.

$config['global_xss_filtering'TRUE

And yes, you can use

$this->input->post(); 

as well.

 Signature 

“In Code We Trust.”


CI Library : Gas ORM | Proxy

 
Posted: 08 November 2011 12:31 AM   [ # 20 ]   [ Rating: 0 ]
Avatar
Joined: 2008-03-19
164 posts
toopay - 06 November 2011 09:53 PM

@ardinotow, :
1. Make sure you download the latest version : here

2. Your user’s relationship, should refer to class name, not table name. Gas will take care your table name, primary key, relationship and other stuff automatically. So if you have wifes as your user’s one-to-one relationship, your user model should have :

public $relations = array(
    
'has_one' => array('wifes' => array()),
); 

3.Then you can create a controller contain :

$users Gas::factory('user')->with('wifes')->all();

foreach(
$users as $single_user)
{
   var_dump
($single_user->wifes);
   echo 
$single_user->name;
   
$wife_name = (empty($single_user->wifes)) ? '' $single_user->wifes->name// dipakai bila menggunakan with();
   
   
echo $wife_name;
   echo 
'<br>';

Tolong konfirmasi, kalau-kalau masih ada isu soal ini atau sudah fix, ya. smile

The latest revision has solved my problems. Yet, I have one more question smile. If I have non standard foreign key on wife table, for example: I have u_id instead of user_id that refer to user.id, how to make that relation on my gas model ? Thanks.

 Signature 

AutoACL - Access Control Library++ with Very Private Page (VPP) Control
AutoCRUMB - The simplest breadcrumb helper ever
Autocrumb on bitbucket
Integrate CI 2 with Eclipse
———————————————————————————————-
Website: ardinoto.blogspot.com

 
Posted: 08 November 2011 12:42 PM   [ # 21 ]   [ Rating: 0 ]
Avatar
Joined: 2010-12-20
1591 posts

Updated to v.1.1.2

Changes :
Support custom key name and cutom table name, in relationship properties.

For convention and example, see public gist for Gas.

 

 Signature 

“In Code We Trust.”


CI Library : Gas ORM | Proxy

 
Posted: 09 November 2011 05:54 AM   [ # 22 ]   [ Rating: 0 ]
Avatar
Joined: 2008-03-19
164 posts

Just updating and custom foreign key works perfectly.
But, I got one more question or maybe asking for a new feature. My table name contains prefix and suffix. Prefix is configurable via config.php which is

$config['my_db_prefix''qe_'

Also, my suffix is depends on user’s session data.
Below script can describe my problem (for simplicity I made my prefix and suffix has empty value).

This is models/wifes_gas.php

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class 
Wifes extends Gas {

 
//public $table = 'wife';
 
 
public $relations = array(
    
'belongs_to' => array('user' => array()),
 );

 function 
__construct() 
 
{
  $prefix 
''// just dummy for test purpose
  
$suffix ''// just dummy for test purpose
  
$CI =& get_instance();
  
//$prefix = $CI->load->config->item('my_db_prefix'); // to get prefix 
  //$suffix = $CI->tablename->get_suffix(); // to get suffix
  
$this->table $prefix.'wife'.$suffix;
 
}
 
 
 
function _init()
 
{

 }

And, this is my controller

$users Gas::factory('user')->with('wifes')->all();

  foreach(
$users as $single_user)
  
{
   
//var_dump($single_user->wifes);
   
echo $single_user->name;
   
$wife_name = ($single_user->wifes == FALSE) ? '' $single_user->wifes->name// dipakai bila menggunakan with('user_profiles');

   
echo ' - '.$wife_name;
   echo 
'<br>';
  

If I run that controller, I can got all user’s name but without the wife’s name. Please help me

Many many thanks…

 Signature 

AutoACL - Access Control Library++ with Very Private Page (VPP) Control
AutoCRUMB - The simplest breadcrumb helper ever
Autocrumb on bitbucket
Integrate CI 2 with Eclipse
———————————————————————————————-
Website: ardinoto.blogspot.com

 
Posted: 09 November 2011 11:20 AM   [ # 23 ]   [ Rating: 0 ]
Avatar
Joined: 2010-12-20
1591 posts

@ardinotow

All of your tables have same prefix and suffix? Or is it different between each other?

Or, you mean database prefix in config/database.php, this line :

$db['default']['dbprefix'''

yes?

If yes, because Gas is using CI AR, it will automatically doing that for you. So if you have set above setting(dbprefix), your $table properties can contain only ‘wifes’ (or leave it blank, if it same with your Gas model’s name), without any prefix even if your real table in your database have prefix. Also, you shouldnt have constructor in your Gas models, to craft your table’s name like that, remove it.

 

 Signature 

“In Code We Trust.”


CI Library : Gas ORM | Proxy

 
Posted: 09 November 2011 04:33 PM   [ # 24 ]   [ Rating: 0 ]
Avatar
Joined: 2008-03-19
164 posts
toopay - 09 November 2011 11:20 AM

@ardinotow

All of your tables have same prefix and suffix? Or is it different between each other?

Or, you mean database prefix in config/database.php, this line :

$db['default']['dbprefix'''

yes?

If yes, because Gas is using CI AR, it will automatically doing that for you. So if you have set above setting(dbprefix), your $table properties can contain only ‘wifes’ (or leave it blank, if it same with your Gas model’s name), without any prefix even if your real table in your database have prefix. Also, you shouldnt have constructor in your Gas models, to craft your table’s name like that, remove it.

 

All my tables have the same prefix, and yes I will use

$db['default']['dbprefix'''


But, how about suffix?
The suffix is depends on user’s session, so I create a library to get table’s suffix. My company made an ERP that can hold several companies in one installment. We decide to store different company’s data on one database with different suffix. So, If users are from company A, they will get data from qe_vendor_001, for users from company B, they will get data from qe_vendor_002, and so on.
I use constructor because I think from it I can load my suffix form library : $CI->tablename->get_suffix().
Thanks.

 Signature 

AutoACL - Access Control Library++ with Very Private Page (VPP) Control
AutoCRUMB - The simplest breadcrumb helper ever
Autocrumb on bitbucket
Integrate CI 2 with Eclipse
———————————————————————————————-
Website: ardinoto.blogspot.com

 
Posted: 09 November 2011 09:12 PM   [ # 25 ]   [ Rating: 0 ]
Avatar
Joined: 2010-12-20
1591 posts

Updated to v.1.2.0

Changes :
- Custom relationship setting (through, foreign_key, foreign_table)
- Hooks points callback(_before_check, _after_check, _before_save, _after_save, _before_delete, _after_delete)

@ardinotow, if you need to load library/helper or set/overide class properties to used later, use _init (it works similar with constructor)

 Signature 

“In Code We Trust.”


CI Library : Gas ORM | Proxy

 
1 of 19
1