EllisLab text mark
Advanced Search
17 of 18
17
   
Gas ORM
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);
        ..............
}

}

 
Posted: 22 August 2012 05:16 AM   [ Ignore ]   [ # 256 ]   [ Rating: 0 ]
Joined: 2011-03-15
4 posts

I added some code in Gas.php file to help for my work:

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:

$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:

$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?

 
Posted: 22 August 2012 07:50 PM   [ Ignore ]   [ # 257 ]   [ Rating: 0 ]
Joined: 2012-08-15
2 posts

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,

 
Posted: 23 August 2012 05:18 AM   [ Ignore ]   [ # 258 ]   [ Rating: 0 ]
Avatar
Joined: 2010-12-20
1586 posts

@lnguyen, what exactly you need.

@jameshang, thats how ActiveRecord ORM works. If you need more adjustment, consider to write Gas ORM extension.

 Signature 

“In Code We Trust.”


CI Library : Gas ORM | Proxy

 
Posted: 23 August 2012 10:42 PM   [ Ignore ]   [ # 259 ]   [ Rating: 0 ]
Joined: 2011-03-15
4 posts

@toopay: may be count_all_result() function is not working. So you can check it or guide me how can i count all record with my conditions.

———————————-
Now i added code in Gas.php file and it working good:

public function count()
{
    
return count($this->select($this->primary_key)->all());
 
Posted: 25 August 2012 07:46 PM   [ Ignore ]   [ # 260 ]   [ Rating: 0 ]
Avatar
Joined: 2012-06-09
82 posts

Hi, I’m doing something like this:

$all_users Model\User::with('blog')->all();

                foreach (
$all_users as $some_user)
                
{
                        
echo 'User ' .$some_user->username.' and he seems have several kids:';

                        foreach (
$some_user->blog() as $blog)
                        
{
                            
echo '<br>';
                            echo 
'<br>';
                            echo 
'<br>';
                            echo 
'<br>';
                            echo 
$blog->title ;
                            echo 
'<br>';
                            echo 
'<br>';
                            echo 
'<br>';
                            echo 
'<br>';
                        

 

But why the output is:

User kevin and he seems have several kids:User francie and he seems have several kids:


francies first post


francies second post


francie 3rd 

It is just showing francie’s post, but not showing kevin’s post? Is this a bug?


I enabled CI profiler and the created query is this:

0.0004    SELECT *
FROM (`user`) 
0.0004    SELECT FROM `blogWHERE `blog`.`user_idIN (2

 

 
Posted: 25 August 2012 08:27 PM   [ Ignore ]   [ # 261 ]   [ Rating: 0 ]
Avatar
Joined: 2012-06-09
82 posts

I also tried this one and its giving me the results I wanted:

$all_users Model\User::all();

                foreach (
$all_users as $some_user)
                
{
                        
echo 'User ' .$some_user->username.' and he seems have several kids:';

                        foreach (
$some_user->blog() as $blog)
                        
{
                            
echo '<br>';
                            echo 
'<br>';
                            echo 
'<br>';
                            echo 
'<br>';
                            echo 
$blog->title ;
                            echo 
'<br>';
                            echo 
'<br>';
                            echo 
'<br>';
                            echo 
'<br>';
                        
}

                } 

But the problem is its making this queries:

0.0004    SELECT *
FROM (`user`) 
0.0004    SELECT FROM `blogWHERE `blog`.`user_idIN (2
0.0003    SELECT FROM `blogWHERE `blog`.`user_idIN (1

It always makes a new query for fetching the blog posts of EACH user. Which is not good for performance, so I really wanted to use eager loading like this one:

$all_users Model\User::with('blog')->all(); 

I hope you can resolve the problem. Thanks smile

 

 

 
Posted: 29 August 2012 03:19 AM   [ Ignore ]   [ # 262 ]   [ Rating: 0 ]
Joined: 2012-08-28
10 posts

Hi! I’m trying to use Gas ORM but I’m stuck with a many-to-many relationship.

I’ve two tables A, B linked by a third C table

A fields[idname]
B fields
[idname]
C fileds
[ida_idb_idvalue] 

on C table, a_id and b_id are FK to related tables.

What I’m trying to do is to get for each A item, his name, the name of related B items plus the value from C table.

E.g.

JohnRed10
John
Blue12
Mike
Red11 

This is how I’ve defined relationships

In A model:

self::$relationships = array(
    
'a'  => ORM::has_many('\\Model\\B\\A => \\Model\\A')
); 

In B model:

self::$relationships = array(
    
'b'  => ORM::has_many('\\Model\\B\\A => \\Model\\B')
); 

In C model:

self::$relationships = array(
    
'b' => ORM::belongs_to('\\Model\\B'),
    
'a' => ORM::belongs_to('\\Model\\A'),
); 

Then I get some data using this code:

$data['items'Model\A::with('b')->all(); 

So I can use it into view

foreach ($items as $a{
    
foreach ($a->b() as $b{
        
// Here I need to show the value field from C table
    
}

And now the question, does this query $data[‘items’] = Model\A::with(‘b’)->all(); retrieves C table data too?

 
Posted: 30 August 2012 12:31 PM   [ Ignore ]   [ # 263 ]   [ Rating: 0 ]
Avatar
Joined: 2010-12-20
1586 posts

No. But you could specify has_many C relationship in your A entity. Btw, this is thread for older version, go to this thread if you have further question on Gas ORM 2.

 Signature 

“In Code We Trust.”


CI Library : Gas ORM | Proxy

 
Posted: 05 September 2012 11:53 AM   [ Ignore ]   [ # 264 ]   [ Rating: 0 ]
Joined: 2008-11-12
4 posts

Hi,

Just like to know if its possible to use memcache for the caching Gas is doing?

 
Posted: 04 October 2012 01:46 PM   [ Ignore ]   [ # 265 ]   [ Rating: 0 ]
Joined: 2011-03-15
4 posts

I found a bug.
If you use join with limit conditions. Limit is return 0.
Example:

//some code...
$results Gas::factory('sections')->select('sections.*, buildings.name as bname, directions.name as dname')
                 ->
order_by($sortname$sortorder)
   ->
left_join_buildings('buildings.id = sections.building_id')
   ->
left_join_directions('directions.id = sections.direction_id')
   ->
limit($limit$offset)
   ->
all();
echo 
Gas::factory('sections')->last_sql();

//result
SELECT ... LIMIT 0 

I’m fixed. In file Gas.php line 5097.

//add code: and $type != 'limit' after $node
if ( ! in_array($type$preserve) and $type == $node and $type != 'limit')
{
    
//...

Sorry for my EL.

 
17 of 18
17