Permalink
Browse files

More updates to ORM

  • Loading branch information...
1 parent 2740e11 commit 175c8b8c2b71cd39edd09920db7ada29f52b6b37 Shadowhand committed Jun 1, 2007
Showing with 68 additions and 9 deletions.
  1. +62 −0 application/config/relationships.php
  2. +3 −3 system/libraries/MY_Loader.php
  3. +3 −6 system/libraries/ORM.php
@@ -0,0 +1,62 @@
+<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
+/*
+| -------------------------------------------------------------------
+| TABLE RELATIONSHIPS
+| -------------------------------------------------------------------
+| This file specifies relationships between fields and tables. This
+| configuration is used for ORM.
+|
+| -------------------------------------------------------------------
+| Instructions
+| -------------------------------------------------------------------
+|
+| Please define each of the table relationships using the following
+| keywords:
+|
+| belongs_to - object "belongs to" another object
+| has_one - object "has one" child object
+| has_many - object "has many" child objects
+| belongs_to_many - object "belongs to many" objects
+| alias_for - object is an "alias for" another object
+|
+*/
+
+$config = array(
+ // Backends
+ 'backend' => array(
+ 'belongs_to_many' => array('sites')),
+ // Contracts
+ 'contract' => array(
+ 'belongs_to' => array('customer', 'vendor'),
+ 'has_one' => array('status', 'service')),
+ // Customers
+ 'customer' => array(
+ 'has_many' => array('contacts', 'users'),
+ 'has_one' => array('status')),
+ // Groups
+ 'group' => array(
+ 'belongs_to_many' => array('users')),
+ // Notes
+ 'note' => array(
+ 'belongs_to' => array('task', 'user')),
+ // Services
+ 'service' => array(
+ 'has_one' => array('category')),
+ // Sites
+ 'site' => array(
+ 'belongs_to' => array('contract'),
+ 'has_one' => array('domain', 'backend')),
+ // Tasks
+ 'task' => array(
+ 'belongs_to' => array('contract')),
+ // Users
+ 'user' => array(
+ 'belongs_to' => array('customer'),
+ 'has_many' => array('groups')),
+ // Vendor
+ 'vendor' => array(
+ 'belongs_to' => array('vendor'),
+ 'has_many' => array('vendors'))
+);
+
+?>
@@ -22,11 +22,11 @@ function orm($table, $where = FALSE)
if ($table == FALSE)
return FALSE;
+ $this->helper('inflector');
+ $this->config('relationships', TRUE);
if ( ! class_exists('CI_DB'))
{
- $CI =& get_instance();
- $CI->load->database();
- unset($CI);
+ $this->database();
}
require_once($this->_ci_find_class('ORM'));
View
@@ -40,7 +40,6 @@ class Core_ORM {
// Must always be FALSE here
private $model_loaded = FALSE;
private $model_parent = FALSE;
- private $model_cache = array();
private $model_errors = array();
/**
@@ -52,10 +51,9 @@ public function __construct($table)
{
// Need access to some CI things
$CI =& get_instance();
- $CI->load->helper('inflector');
-
$this->db =& $CI->db;
// Set table prefix
+ $this->relationships = $CI->config->item($table, 'relationships');
$this->prefix = $table.'_';
$this->table = plural($table);
// Load model cache from database
@@ -262,7 +260,7 @@ public function &__get($key)
* @param mixed variable value
* @return bool
*/
- public function __set($key, $value)
+ public function __set($key, $value)
{
$key = (string) $key;
@@ -656,7 +654,6 @@ private function _load_cache($rebuild = FALSE)
$table_exists = TRUE;
continue;
}
-
$cache[$table] = $this->db->table_data($table);
}
@@ -805,7 +802,7 @@ private function _load_cache($rebuild = FALSE)
}
$this->fields = $cache[$this->table]['fields'];
- $this->relationships = $cache[$this->table]['relationships'];
+ // $this->relationships = $cache[$this->table]['relationships'];
}
// --------------------------------------------------------------------

0 comments on commit 175c8b8

Please sign in to comment.