Welcome Guest, Not a member yet? Register   Sign In
Gas ORM
#71

[eluser]toopay[/eluser]
@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.
#72

[eluser]Lars Germ[/eluser]
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?
#73

[eluser]frozenmaiden[/eluser]
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

Code:
company                company_property          property
-------               ----------------           --------
id            <---&gt;        id                       id
name                       company_id               name
                           property1_id    <---&gt;
                           property2_id    <---&gt;
                           property3_id    <---&gt;

How to set the relations for this case?


#74

[eluser]Ashirra[/eluser]
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
Code:
$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.

#75

[eluser]Keyur Shah[/eluser]
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!
#76

[eluser]Unknown[/eluser]
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?
#77

[eluser]toopay[/eluser]
@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


#78

[eluser]jameshang[/eluser]
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:

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

class ThisModel extends ORM{

}

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

class ThisController extends CI_Controller{

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

}
#79

[eluser]lnguyen[/eluser]
I added some code in Gas.php file to help for my work:
Code:
public function conditions($conditions = array())
{
  foreach($conditions as $field => $args)
  {
   $recorder = array($field => $args);
   Gas_janitor::tape_record($this->model(), $recorder);
  }

  return $this;
}
This is my code:

Code:
$page = isset($_POST['page']) ? $_POST['page'] : 1;
$limit = isset($_POST['rp']) ? $_POST['rp'] : 20;
$sortname = isset($_POST['sortname']) ? $_POST['sortname'] : 'name';
$sortorder = isset($_POST['sortorder']) ? $_POST['sortorder'] : 'desc';
$query = isset($_POST['query']) ? $_POST['query'] : false;
$qtype = isset($_POST['qtype']) ? $_POST['qtype'] : false;
$offset = (($page-1) * $limit);

$model = Gas::factory('building');
$args = array();
if($query)
{
     $args['like'] = array($qtype, $query);
}

$total = count($model->select(Gas::factory('building')->primary_key)->conditions($args)->all());

// Populate result
$args['order_by'] = array($sortname, $sortorder);
$args['limit'] = array($limit, $offset);

$results = $model->conditions($args)->with('direction')->all();
This is work. But when I use:
Code:
$total = $model->conditions($args)->count_all_results();
I have an error:
Cannot continue executing Gas_core::__call without any passed parameter.

I use Gas v1.4. I don't want to use previous code. Can you help me?
#80

[eluser]jameshang[/eluser]
Is there any way to get array version of the query result?

for example, when we use find_by_column('xxx'), the result is an array of objects,
I'd like to have a 2-D array, an array of arrays.

Thanks,




Theme © iAndrew 2016 - Forum software by © MyBB