EllisLab text mark
Advanced Search
11 of 15
11
   
Gas ORM 2
Posted: 25 September 2012 09:43 PM   [ Ignore ]   [ # 161 ]   [ Rating: 0 ]
Joined: 2011-10-14
5 posts

Cool its solve my problem but only for 1 table relationship.

Is it posible to define a “primary_key/foreign_key” per table relationship like:

self::$relationships = array (
  
'table_1' => ORM::has_one('\\Model\\table_1',array('primary_key'=>'primary_key_1')),
  
'table_2' => ORM::has_many('\\Model\\table_2',array('primary_key'=>'primary_key_2'))
  
'table_3' => ORM::has_many('\\Model\\table_3',array('primary_key'=>'primary_key_3','foreign_key'=>'foreign_key_3'))
); 

Thanks toopay, gas orm raks its super lightweight.

 
Posted: 25 September 2012 10:16 PM   [ Ignore ]   [ # 162 ]   [ Rating: 0 ]
Avatar
Joined: 2010-12-20
1590 posts

@Test32, No, version 1.x.x support that kind of syntax. In version 2.x.x, you define foreign key in the “target” entity, just like what you did in your database schema.

 Signature 

“In Code We Trust.”


CI Library : Gas ORM | Proxy

 
Posted: 25 September 2012 11:31 PM   [ Ignore ]   [ # 163 ]   [ Rating: 0 ]
Joined: 2011-10-14
5 posts

But its nice you have a functionality like that maybe put like an optional.
Is it the gas orm version 1.x.x compatible to CI 2.1?

Im lazy to use the AR now since i started using gas orm smile
OK, Thank you

 
Posted: 26 September 2012 06:52 PM   [ Ignore ]   [ # 164 ]   [ Rating: 0 ]
Joined: 2012-08-28
6 posts

I have defined a subclass of ORM for my base models:

class Ego_Base extends ORM
{
...

And I use it like

class Catalog extends Ego_Base
{
...

The problem is that I cannot load the child class, when I do for instance:

$all_elements Model\Catalog::all(); 

I get:

PHP Fatal error:  Class 'Model\\Catalog' not found 

What can I do? The base model is in the “models” folder as well.

 

 
Posted: 27 September 2012 12:06 AM   [ Ignore ]   [ # 165 ]   [ Rating: 0 ]
Avatar
Joined: 2010-12-20
1590 posts

@Omegote, show your base models.

 Signature 

“In Code We Trust.”


CI Library : Gas ORM | Proxy

 
Posted: 27 September 2012 07:03 AM   [ Ignore ]   [ # 166 ]   [ Rating: 0 ]
Joined: 2012-08-28
6 posts
toopay - 27 September 2012 12:06 AM

@Omegote, show your base models.

Don’t worry, finally I found the problem… Mistakenly I had deleted the line where I was loading gas orm… What a shame xD

 
Posted: 20 October 2012 03:17 PM   [ Ignore ]   [ # 167 ]   [ Rating: 0 ]
Joined: 2011-05-18
15 posts

The Home of Gas ORM is not loading… i need some documentation of How to Use GasORM

 
Posted: 20 October 2012 03:49 PM   [ Ignore ]   [ # 168 ]   [ Rating: 0 ]
Avatar
Joined: 2010-12-20
1590 posts

@Crackz0r… Its always on : http://www.webpagetest.org/result/121020_2Q_B6J/

 Signature 

“In Code We Trust.”


CI Library : Gas ORM | Proxy

 
Posted: 26 October 2012 02:37 PM   [ Ignore ]   [ # 169 ]   [ Rating: 0 ]
Joined: 2011-08-11
3 posts

Hi Toopay,

Thank you very much for writing this library.
I’m encoutering the same problem as Slarv and Joao Barbosa.

Fatal error: Cannot instantiate abstract class Gas\ORM in blabla/sparks/gas/2.1.1/third_party/gas/classes/orm.php on line 320

I’m also on PHP version 5.3.3
The Late Static Binding example from php.com is working fine;

<?php
class A {
    
public static function who() {
        
echo __CLASS__;
    
}
    
public static function test() {
        
static::who(); // Here comes Late Static Bindings
    
}
}

class extends A {
    
public static function who() {
        
echo __CLASS__;
    
}
}

B
::test();
?> 

I also tried your workaround;

final public static function make($record = array())
{
   $lsb_class 
get_called_class();

   return new 
$lsb_class($record); 


I tried to echo the $lsb_class. I found the following;
Before the make() function is applied on “Gas\ORM” it is successfuly applied on another class “Model\Objectname”. This is an object in my data scheme which has been configured as a one_to_many relationhip.
But when make() gets called for the second time ($lsb_class = “Gas\ORM”) the error occurs.

Do you have any idea what I can try to solve this problem?

Thank you in advance for your time.

Regards, Erik

 
Posted: 28 October 2012 01:26 PM   [ Ignore ]   [ # 170 ]   [ Rating: 0 ]
Avatar
Joined: 2010-12-20
1590 posts

@erikver : any other pointer on how to reproduce this? some used code perhaps?

 Signature 

“In Code We Trust.”


CI Library : Gas ORM | Proxy

 
Posted: 28 October 2012 02:27 PM   [ Ignore ]   [ # 171 ]   [ Rating: 0 ]
Joined: 2011-08-11
3 posts

@toopay; Thanks for your reply.

I’m using the following models (simplified version);

Model 1 (Company);

<?php namespace Model;

use 
\Gas\Core;
use 
\Gas\ORM;

class 
Company extends ORM {

 
public $primary_key 'id';


 function 
_init()
 
{
 
  
// Define relationships
  
self::$relationships = array(
   
'businessunit' => ORM::has_many('\\Model\\Businessunit')
  );
  
  
self::$fields = array(
   
'id' => ORM::field('auto[10]'),
   
'name' => ORM::field('char[200]'),
   
'created_at' => ORM::field('datetime'),
   
'modified_at' => ORM::field('datetime'),
  );

 
}

Model 2 (Businessunit);

<?php namespace Model;

use 
\Gas\Core;
use 
\Gas\ORM;

class 
Businessunit extends ORM {
 
 
public $primary_key 'id';

 function 
_init()
 
{
  self
::$relationships = array (
   
'company' => ORM::belongs_to('\\Model\\Company')
  );
  
  
self::$fields = array(
   
'id' => ORM::field('auto[10]'),
   
'name' => ORM::field('char[200]'),
   
'created_at' => ORM::field('datetime'),
   
'modified_at' => ORM::field('datetime'),
  );

 
}

The businessunit database table has a field company_id.

The controller;

class Test extends CI_Controller {
 
 
public function __construct() {
  parent
::__construct();
  
//$this->output->enable_profiler(TRUE);
  
 
 
}
 
 
public function index(){

    $companies 
Model\Company::all();
    
    
print_r($companies);
 
 
}

But isn’t it an php fundamental instantiating an abstract class is illegal?
From the php manual:

Classes defined as abstract may not be instantiated,....

http://php.net/manual/en/language.oop5.abstract.php

Or is it not the intention to instantiate “gas/orm”? I think it is happening in line 830;
$gas = self::make();

If i get it right, this line results in the instantiation of “abstract class ORM” (which is illegal?).

 
Posted: 28 October 2012 06:55 PM   [ Ignore ]   [ # 172 ]   [ Rating: 0 ]
Avatar
Joined: 2010-12-20
1590 posts

I think we have PHP version incompatible issue here. make method is returning new static, so we’re not trying to instantiate the abstract. Here you could see the analog assertion on how late static binding works, on supported php environment(5.3++) : http://codepad.viper-7.com/cuGBre

What are your php version btw?

 Signature 

“In Code We Trust.”


CI Library : Gas ORM | Proxy

 
Posted: 29 October 2012 09:13 AM   [ Ignore ]   [ # 173 ]   [ Rating: 0 ]
Joined: 2011-08-11
3 posts

Hi Toopay,

phpinfo: PHP Version 5.3.3-7+squeeze14

The example you provided is working fine..
Your example is valid for calls from child classes like; Company::all().

But it goes wrong for calls like to abstract class directly like ORM::has_many(). Which occur in the models for defining the relationships.

Isn’t it this what’s happening?;

<?php
Abstract class ORM
{

 
final public static function make($record = array())
 
{
  
return new static($record);
 
}
 
 
public static function __callStatic($name$arguments)
 
{
  $gas 
self::make();
 
}
 
}

print_r
(ORM::has_many()); //Results in the error

?> 

http://codepad.viper-7.com/Z8OQLY

 
Posted: 31 October 2012 03:47 PM   [ Ignore ]   [ # 174 ]   [ Rating: 0 ]
Avatar
Joined: 2010-12-20
1590 posts

@erikver :
As you can see, ORM::has_many is a static call, and it supposed to not require any instantiation if it was called via object context.

Here i try to emulate the full life-cycle of relationships initialization in any model sub-classes : http://codepad.viper-7.com/xxfrom , notice that the override method is calling relationships method on ORM, which is a static method without any abstract instantiation: its a valid call.

 Signature 

“In Code We Trust.”


CI Library : Gas ORM | Proxy

 
Posted: 01 November 2012 05:38 AM   [ Ignore ]   [ # 175 ]   [ Rating: 0 ]
Joined: 2012-11-01
5 posts

I have two tables. One with events and one with several performances to specific events. I want to list all my events ordered by the performance with the closest date. Is this possible? Thanks.

 
11 of 15
11