EllisLab text mark
Advanced Search
17 of 18
17
   
Gas ORM
Posted: 14 April 2012 05:19 AM   [ Ignore ]   [ # 241 ]   [ Rating: 0 ]
Joined: 2011-01-01
11 posts

Hi Toopay,

What does this mean?

“Unique fields is non-uniformal validation rule, and by doing this way, we doesnt pollute our above fields datatype definition.”

I did this in my gas model:

$this->_unique_fields = array(‘email’, ‘username’);

but somehow, there are no validation errors that get generated if I enter the same email id again.

I can do a hook but just wondering if you have something built into Gas ORM already?

 
Posted: 14 April 2012 05:58 AM   [ Ignore ]   [ # 242 ]   [ Rating: 0 ]
Avatar
Joined: 2010-12-20
1586 posts

@fountainhead,
I’ve just run unit test for version 1.4.3 and it works well.

This is typical save process, you can try :

// Use factory method, instead instantiate it like :
//    $new_user = new User();
$new_user Gas::factory('user');

// Assume you already put the new entries data into $data variable
$new_user->fill($data);

// Dont forget to pass TRUE 
if ($new_user->save(TRUE))
{
   
echo 'success';
}
else
{
   
echo 'fails';

   
// Here you should see the validation error, 
   // if you already set unique fields in your model
   
var_dump($new_user->errors);

 Signature 

“In Code We Trust.”


CI Library : Gas ORM | Proxy

 
Posted: 14 April 2012 06:13 AM   [ Ignore ]   [ # 243 ]   [ Rating: 0 ]
Joined: 2011-01-01
11 posts

Thanks Toopay. Realize it works but just doesn’t show up in
<?php echo validation_errors(); ?>

Not related to Gas ORM, but is there a way I can have them transfer the messages from $new_user->errors to form validation so that I can use <?php echo validation_errors(); ?>

 
Posted: 14 April 2012 06:43 AM   [ Ignore ]   [ # 244 ]   [ Rating: 0 ]
Avatar
Joined: 2010-12-20
1586 posts

@fountainhead,

You can extend CI form validation. Create file on application/libraries/MY_Form_validation.php contain something like :

<?php

class MY_Form_validation extends CI_Form_validation {
 
   
public function set_gas_error($errors = array())
   
{
      $this
->_error_array array_merge($errors$this->_error_array);
   
}

Then from my previous example, you can assign the errors :

$this->form_validation->set_gas_error($new_user->errors); 

This way if you echoing validation_errors in your view, the errors within your gas model will be included.

 Signature 

“In Code We Trust.”


CI Library : Gas ORM | Proxy

 
Posted: 07 May 2012 02:02 PM   [ Ignore ]   [ # 245 ]   [ Rating: 0 ]
Joined: 2011-01-01
11 posts

Hi ... sorry basic question

I have a table called “pin” and every pin has one or zero “file”

My pin model is as follows:

class Gas_pin extends Gas {
    
public $table 'default_str_gas_pins';
    public 
$primary_key 'id';

    
// Every Gas_pin has a file
 
public $relations = array('has_one' => array('file' => array('foreign_key'=>'pin_image_1')));

My “file” model is as follows

class file extends Gas {
    
public $table 'default_files';
    public 
$primary_key 'id';

My “pin” table has a field called “pin_image_1” which links up with the “file” table ...

I am unable to get the relationship working ...

I want to do:

$pin = new Gas_pin();
        
$pins $pin->with('file')->all(); 

I get the following error:
Model gas_pin located, but missing relationship properties.

Please help!

 
Posted: 07 May 2012 02:43 PM   [ Ignore ]   [ # 246 ]   [ Rating: 0 ]
Avatar
Joined: 2010-12-20
1586 posts

@fountainhead,

The error message that raised, should give you a clear idea whats happened. When you set a relationship that did not follow Gas convention, you need to set it up on both model(s). Refer to Relationship section within doc for version 1.x.

 Signature 

“In Code We Trust.”


CI Library : Gas ORM | Proxy

 
Posted: 07 May 2012 03:00 PM   [ Ignore ]   [ # 247 ]   [ Rating: 0 ]
Joined: 2011-01-01
11 posts

Hi Toopay ... thanks ... I tried few more steps to make it work .....
I am having trouble how to do the custom overriding ..

Can you please help?

The following works:

class File extends Gas {
    
public $table 'default_files';
    public 
$primary_key 'id';

 public 
$relations = array(
       
'has_many' => array('gas_pin' => array('foreign_table'=>'default_str_gas_pins''foreign_key'=>'pin_image_1')),
      );
class Gas_pin extends Gas {
    
public $table 'default_str_gas_pins';
    public 
$primary_key 'id';

 public 
$relations = array(
      
'belongs_to' => array('file' => array('foreign_key'=>'pin_image_1')),
     );

But, I actually think belongs_to in the gas_pin is not correct ... how can I can modify gas_pin to has_one “file”?

 
Posted: 08 May 2012 02:30 AM   [ Ignore ]   [ # 248 ]   [ Rating: 0 ]
Avatar
Joined: 2010-12-20
1586 posts

@fountainhead,

What you mean incorrect? Could you make some scenario, of how you want to process your data? Because for me, above configuration seems fine, if you intend to set up one-to-many relationship (mean one record in file could have several records in pin, and one record in pin could have only one related record in file). If you want to set up one-to-one relationship (mean one record in file could only have one record in pin, vice-versa), all you have to do is change the relations property within file entity from has_many to has_one.

 Signature 

“In Code We Trust.”


CI Library : Gas ORM | Proxy

 
Posted: 03 June 2012 09:27 AM   [ Ignore ]   [ # 249 ]   [ Rating: 0 ]
Avatar
Joined: 2012-06-02
3 posts

I can’t figure it out. How can I auto-generate models from an existing database? I set $config[‘gas’][‘auto_create_models’] = TRUE;. But what’s the next step? Sorry for this question, but I can’t find any information about this even not in the documentation.

EDIT:
Okay I found it by myself. If you set $config[‘gas’][‘auto_create_models’] to TRUE then GAS creates the models immediately after the first page refresh. GOOD! to easy.

The problem was, that I installed GAS first with sparks. And with sparks GAS isn’t working. So now I’ve installed GAS manually and everthing works perfectly!

Another question which I posted here as well: Why is it necessary to download the whole CI repo, when you want to install GAS with sparks?

 
Posted: 20 June 2012 01:09 AM   [ Ignore ]   [ # 250 ]   [ Rating: 0 ]
Joined: 2009-10-19
17 posts

Hi toopay, Thanks for your great work!! I really like this ORM

I have some case that make me confuse how to do it with GAS

I have 3 three table company, company_number, n property

company have foreign key company_id on table company_property

property have property1_id,property2_id,property3_id as foreign_key on table company_property

company                company_property          property
-------               ----------------           --------
id            <--->        id                       id
name                       company_id               name
                           property1_id    
<--->
                           
property2_id    <--->
                           
property3_id    <---> 

How to set the relations for this case?

 

 

 
Posted: 28 June 2012 02:34 PM   [ Ignore ]   [ # 251 ]   [ Rating: 0 ]
Joined: 2012-06-28
4 posts

Hello

I have a problem with your dummy class.

if I use all(), first(), last() it works fine an prints the table properly, but not with limit().

code like

$data['frontusers'Model\Frontuser::dummy()->last()->explain(); 

I couldn’t find a clue for this problem.

Thanks for your help.

Ashirra

PS: nice work, I have 23 tables with all relations you can imagine and it works fine till now.

 

 
Posted: 09 July 2012 02:26 AM   [ Ignore ]   [ # 252 ]   [ Rating: 0 ]
Avatar
Joined: 2008-09-22
30 posts

thanks for your hard work, this looks really interesting.

i am browsing through the hooks and don’t see one for “after get”. so, basically, something that i can use to modify results after they are retrieved, but before sending to the controller. please let me know if you have any plans on adding that.

thanks!

 
Posted: 23 July 2012 06:04 AM   [ Ignore ]   [ # 253 ]   [ Rating: 0 ]
Joined: 2012-07-23
1 posts

thx for this great ORM.

I have some problems with error handling. for example dublicate key errors.
how should I handle them? if I get db errors they throw directly by CI ...

how can I catch them?

and whats the best way for inserting many rows at the same time?

 
Posted: 23 July 2012 12:53 PM   [ Ignore ]   [ # 254 ]   [ Rating: 0 ]
Avatar
Joined: 2010-12-20
1586 posts

@247am, CI did not throw exception (you can’t catch anything), it just outputing the error message, so nothing you can do about that. But to avoid db error message, you could either set the ENVIRONMENT to ‘production’ and it will suppress any php warning or set db_debug parameter to false in config/database.php

 

 Signature 

“In Code We Trust.”


CI Library : Gas ORM | Proxy

 
Posted: 15 August 2012 10:20 PM   [ Ignore ]   [ # 255 ]   [ Rating: 0 ]
Joined: 2012-08-15
2 posts

If we put model classes in other folders (rather than default application\models),

assume the model class is ThisModel,  and put it into \AAA\BBB\CCC folder.

1. in application\config\autoload.php, add following line:

spl_autoload_register(array(‘MY_Loader’, ‘load_gas_orm_model’));

2. then in application/core/MY_Loader.php, add the following method:

  public static function load_gas_orm_model($class)
  {
     
      $arr = explode(’\\’, strtolower($class));
      $path = ‘path/to/parent/folder/’. strtolower($class) . ‘.php’;
      $path = str_replace(’\\’,’/’, $path);
      if (file_exists($path)) {
        require_once $path;
      }
  }

3. in model class:

<?php
namespace AAA\BBB\CCC;    //AAA, BBB, CCC is mapping to our folder structure

class ThisModel extends ORM{

}

4. in controller class:
<?php
use AAA\BBB\CCC\ThisModel;

class ThisController extends CI_Controller{

  function this_action()
{
    $record = ThisModel::find(1);
        ..............
}

}

 
17 of 18
17