EllisLab text mark
Advanced Search
3 of 18
3
   
Gas ORM
Posted: 11 November 2011 11:06 AM   [ Ignore ]   [ # 31 ]   [ Rating: 0 ]
Avatar
Joined: 2010-12-20
1590 posts

@JonoB,

Your models can have several callbacks to interact with internal Gas lifecycle. Look at hooks point callbacks, available points are :

_before_check() : run before validate your input (if you set your fields rule in _init function, and you passing TRUE within save() method).

_after_check() : run after validate your input.

_before_save() : run before INSERT or UPDATE operation.

_after_save() : run after above operation.

_before_delete() : run before DELETE operation.

_after_delete() : run after DELETE operation.

In above case, you may want to use _before_check or _before_save callback, depend on how you want to doing it.

So, suppose you have some post data like this one :

$_POST = array(
    
'name' => 'Mr. Foo',
    
'email' => 'foo@bar.com',
    
'username' => 'foo',
    
'somefields' => 'Lorem',
    
'otherfields' => 'Ipsum',
);

// and you try to save it
$new_user Gas::factory('user')->fill($_POST);

$new_user->save(TRUE); 

Then in your Gas model, if you want to only save name, email and username, you can executed your own filtering method on _before_save() callback, mean you want to validate all the data, but only several of it will be saved/updated.

// within your Gas model, suppose you set your own properties
public $attributes = array('name''email''username');

//...
//...

function _before_save()
{
    
// Here you can see all populated data, dont try to check $_POST here.
    // Gas has its own mechanism, so overide/change/modify $_POST will not affect anything
    
$old_data $this->filled_fields();
    
    
// Here you can implement your own filtering method
    
$new_data $this->filter_attributes($old_data);

    
// to overide all set data, use set_fields() method
    
$this->set_fields($new_data);

    return 
$this;

This mean you can also modified some (or all) of it, or adding some common fields (like timestamps) before save/update data.

 Signature 

“In Code We Trust.”


CI Library : Gas ORM | Proxy

 
Posted: 12 November 2011 10:33 AM   [ Ignore ]   [ # 32 ]   [ Rating: 0 ]
Joined: 2009-01-21
48 posts

Great job toopay, rly thx!!!!

I have one question: have any technique matter if i load one model in another? i do this, and i want to know if i have some problem because this in case i migrate to Gas.

Nice job man, thx.

 
Posted: 12 November 2011 01:03 PM   [ Ignore ]   [ # 33 ]   [ Rating: 0 ]
Avatar
Joined: 2010-12-20
1590 posts
ClaudioX - 12 November 2011 10:33 AM

I have one question: have any technique matter if i load one model in another?

You mean load a model files manually (more related with autoload models configuration), or use another model instance within a model (if yes, is the foreign model defined in relationship or not)? And what “matter” you mean above, raw performance or what?

The best practice when you using Gas, is defined your table/model relation, and works in thats constraint. Off course you can work with another model, which might not related at all, with factory method (eg, work with sale model in role model, which is not related each other), but that will make your model harder to maintain. Also with clear constraint, you can maximize your queries performance, since with relations properties defined, you can eager load your related model/table.

 Signature 

“In Code We Trust.”


CI Library : Gas ORM | Proxy

 
Posted: 12 November 2011 05:41 PM   [ Ignore ]   [ # 34 ]   [ Rating: 0 ]
Joined: 2009-01-21
48 posts

First, thx for the reply,

I mean:

use another model instance within a model

what “matter” you mean?

Conflicts, key mix, that staffs.

thinking in what you say, the most part of time when i use this, is probaly for what the library is propose to do! tongue rolleye

Let me show:

$this->load->model("page_class");        //table page
$this->load->model("page_data_model");   //table page_data
$this->load->model("page_adress_model"); //table page_adress

$PG     = new Page_class();
$PGData = new Page_data_model();
$PGAdr  = new Page_adress_model();

$PG->setAll();
$PGData->setAll();
$PGAdr->setAll();
$PG->setData($PG->Data);
$PG->setAdr($PG->Adr);
$PG->save(); 
 
Posted: 13 November 2011 02:11 AM   [ Ignore ]   [ # 35 ]   [ Rating: 0 ]
Avatar
Joined: 2010-12-20
1590 posts
ClaudioX - 12 November 2011 05:41 PM

Conflicts, key mix, that staffs.

No, it wouldnt be a matter.

ClaudioX - 12 November 2011 05:41 PM

thinking in what you say, the most part of time when i use this, is probaly for what the library is propose to do! tongue rolleye

I already stated that you can do anything, even if you plan to work with several models within one model, which not related at all (based by your schema) : it will still works.

But with clear constraint, you can gain maximum performance(mean extra benefits).wink

 Signature 

“In Code We Trust.”


CI Library : Gas ORM | Proxy

 
Posted: 13 November 2011 02:18 PM   [ Ignore ]   [ # 36 ]   [ Rating: 0 ]
Avatar
Joined: 2010-12-20
1590 posts

Updated to v.1.3.0

Changes :
Support extensions.

The purpose of an extension is to become a standard interface which you can use, to share common function that utilize either CI Library or your own library, across your Gas models/instances.

I include dummy extension and some implementation example on gasunittest.php, in recent version, just for example to show you how it works, so you can start write yours (based by your application needs).

 Signature 

“In Code We Trust.”


CI Library : Gas ORM | Proxy

 
Posted: 13 November 2011 07:34 PM   [ Ignore ]   [ # 37 ]   [ Rating: 0 ]
Avatar
Joined: 2007-03-17
6 posts

I just want to share my experience in case someone encounter the same scenario such I did.
I was using this great lib with my projects. I have my own subversion repo setup where I always put my projects.

After doing a check out from my repo. My project keeps saying “Fatal error: Cannot redeclare class Users”. I tried
to check if there are any code in my project that redeclares the class but did not found any. My investigation
lead me to a file “application/libraries/Gas.php”.

At line 1024 I added this “OR $file == ‘.svn’”

File      application/libraries/Gas.php
Line 1024 
: if ($file == '.' OR $file == '..' OR $file == '.svn') continue; 

and solved my problem. Now my application is not showing the “Fatal error: Cannot redeclare class Users” anymore.

 
Posted: 13 November 2011 08:00 PM   [ Ignore ]   [ # 38 ]   [ Rating: 0 ]
Avatar
Joined: 2010-12-20
1590 posts

@blueant,

It seems to me that your svn is creating ‘.svn’ folder (it might be a hidden folder) under your models directory, which most likely also contain duplicates of your models files. Since for autoload all model, and for supporting cascade directories, i use standard scandir() method (it just avoid ‘.’ and ‘..’), to scanning recursively all matched models. Could you confirm this, please.

And thanks for reporting, i will added that fix into next commit.

 Signature 

“In Code We Trust.”


CI Library : Gas ORM | Proxy

 
Posted: 13 November 2011 08:56 PM   [ Ignore ]   [ # 39 ]   [ Rating: 0 ]
Avatar
Joined: 2007-03-17
6 posts

Yes you are correct, my project has now a “.svn” folder inside models folder. I think this will always be the case for projects under subversion, the “.svn” folder was created by subversion itself.

 
Posted: 14 November 2011 09:34 PM   [ Ignore ]   [ # 40 ]   [ Rating: 0 ]
Avatar
Joined: 2010-12-20
1590 posts

Updated to v.1.3.1

Changes :
Fix recursive scanning and some fraction of validation mechanism issue(s).

Oh, and one more thing. Seeing someone in PyroCMS suggesting my library, all emails in my inbox asking troubleshoot and all installs statistic (both via Sparks and GitHub), i will fell terrible if i let anyone have to lost an idea when working with Gas ORM, so i create official documentation for it, since several kilobytes of gist file no longer could explain properly what it really is and how to really use it.

As you may aware of my ackward grammar, which is terribely sucks, i also put those documentation source (sphinx source), at Gas ORM repo, so if you care, help me to correct all typos(if you find any) or mispelling grammar and make it more clear for community to read without having their eyes hurts wink

 Signature 

“In Code We Trust.”


CI Library : Gas ORM | Proxy

 
Posted: 15 November 2011 12:27 PM   [ Ignore ]   [ # 41 ]   [ Rating: 0 ]
Joined: 2011-11-15
2 posts

Hi, great stuff.
I’ve tried to install the 1.3.1, and couldn’t run the unit test.
and it get me a simple page of message:
“The Id field was an invalid autoincrement field.”

and in CI log, it has error message of:
‘ERROR - 2011-11-15 16:26:12—> Could not find the language line “auto_check”’

I then ran the unit test of 1.3.0 and it’s working perfectly.
New to this, not sure what’s going wrong.
Could you please fix this?

 
Posted: 15 November 2011 01:13 PM   [ Ignore ]   [ # 42 ]   [ Rating: 0 ]
Avatar
Joined: 2010-12-20
1590 posts

Redownload or just replace Gas.php with my latest commit. Last night i adding several new additional functionalities, to validation mechanism, and forgot to test this new version with old unit testing controller before release (since everything is fine, in other smaller unit testing environment).

 Signature 

“In Code We Trust.”


CI Library : Gas ORM | Proxy

 
Posted: 15 November 2011 01:25 PM   [ Ignore ]   [ # 43 ]   [ Rating: 0 ]
Joined: 2011-11-15
2 posts

perfect, working great right now. Thanks

 
Posted: 15 November 2011 07:07 PM   [ Ignore ]   [ # 44 ]   [ Rating: 0 ]
Avatar
Joined: 2010-12-20
1590 posts

Updated to v.1.3.2

Changes :

1. Fix some fraction of validation mechanism issue(s), its now even can handle PUT data (in case you develop some REST application, and need doing validation on it). Also you now can handle validation error message more freely by accesing errors properties of your gas instance.

2.Adding [min-length,max-length] option directly in field method.

3. Support modular models directories. Previously, Gas will only work if your modules is located within your application folder, since Gas using APPPATH constant as pointer. But now you can specify both your native models directories and your modules models. If you didnt upgrade your config file and doesnt need this functionality, it will still works as before.

I update the documentation as well, to cover recent changes and adding other info about this.

 Signature 

“In Code We Trust.”


CI Library : Gas ORM | Proxy

 
Posted: 17 November 2011 07:17 AM   [ Ignore ]   [ # 45 ]   [ Rating: 0 ]
Avatar
Joined: 2010-12-20
1590 posts

Updated to v.1.3.3

Changes :

1. Fully support latest CI 2.1.0.
2. Better (raw) performance. I change several fraction within compile method, but recent legacy API is not (and will never be) changed.
3. Fix some validation issues, it is a way more stable than previous v.1.3.0.

If you still found some issue(s), if any, please dont hesitate to share it here or in repo (that was i looking for, hidden bugs wink  ).

 Signature 

“In Code We Trust.”


CI Library : Gas ORM | Proxy

 
3 of 18
3