[eluser]kungpoo[/eluser]
I've been tearing my hair out tonight, something that I know has worked for me in the past just doesn't seem to work anymore. To illustrate I have done a fresh install of CI and DMZ on both CI 1.7.2 and 2.0.
Inserted the following into a DB (as simple as possible) -
Code:
CREATE TABLE `artists` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `artists_users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`artist_id` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(10) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Created the models-
Code:
<?php
class Artist extends DataMapper
{
var $has_many = array('user');
function __construct($id=NULL)
{
parent::__construct($id);
}
}
Code:
<?php
class User extends DataMapper
{
var $has_many = array('artist');
function __construct($id=NULL)
{
parent::__construct($id);
}
}
Then did the
controller -
Code:
<?php
class Welcome extends Controller {
function Welcome()
{
parent::Controller();
$this->output->enable_profiler(TRUE);
//$this->load->model('Artist');
//$this->load->model('User'); - neither seem to change things
}
function index()
{
$a = new Artist();
$a->name = 'artist';
$u = new User();
$u->name = 'user';
$u->save($a);
//$a->save($u); - doesn't help to create it either
}
}
But all I get is the following queries being run, the relationship is never created. If the objects are saved separately they are fine but obviously there is no relationship then.
Code:
SELECT * FROM `artists` LIMIT 1
SELECT * FROM `users` LIMIT 1
INSERT INTO `users` (`name`) VALUES ('user')
I've tried it with simple one to one and one to many relationships too but nothing seems to be working for me. Am I missing something glaringly obvious?
Thanks!