Hello!
Gas Orm looks great and I’m super excited to start using it. Chose it over Doctrine and Datamapper.
I am having one issue though.
I have a user_accounts table and a user_credits table with a one-to-one relationship. I believe I set the models up correctly but I’m unable to pull the relationships together in the controller. Can anyone give me a hand?
user.php:
<?php namespace Model;
use \Gas\Core;
use \Gas\ORM;
class User extends ORM {
public $table = 'user_accounts';
public $primary_key = 'userid';
function _init()
{
self::$relationships = array (
'credit' => ORM::has_one('\\Model\\Credit'),
);
self::$fields = array(
'userid' => ORM::field('auto[10]'),
'firstname' => ORM::field('char[50]'),
'lastname' => ORM::field('char[50]'),
'email' => ORM::field('char[100]'),
'password' => ORM::field('char[150]'),
'gender' => ORM::field('char[11]'),
'month' => ORM::field('char[16]'),
'day' => ORM::field('char[10]'),
'year' => ORM::field('int[255]'),
'regdate' => ORM::field('char[16]'),
'regtime' => ORM::field('char[16]'),
'phonenumber' => ORM::field('char[15]'),
'zipcode' => ORM::field('int[11]'),
'type' => ORM::field('char[16]'),
'verified' => ORM::field('int[1]'),
'allow_email' => ORM::field('int[1]'),
'is_advertiser' => ORM::field('int[4]')
);
}
}
credit.php:
<?php namespace Model;
use \Gas\Core;
use \Gas\ORM;
class Credit extends ORM {
public $table = 'user_credits';
public $primary_key = 'userid';
function _init()
{
self::$relationships = array (
'user' => ORM::belongs_to('\\Model\\User'),
);
self::$fields = array(
'userid' => ORM::field('auto[10]'),
'credits' => ORM::field('int[10]'),
'campaigns_viewed' => ORM::field('int[int]')
);
}
}
In my controller, I’m trying to look at how many credits a user has using the following function:
public function orm_test() {
$this->output->enable_profiler("true");
error_reporting(E_ALL);
ini_set('display_errors', '1');
$a = Model\User::find(1)->credit();
echo "<pre>";
print_r($a);
echo "</pre><p>“;<br />
}
</pre>
Running the above code returns the following:
“Fatal error: Call to a member function result_array() on a non-object in /var/www/dev/application/third_party/gas/classes/core.php on line 1591”