Welcome Guest, Not a member yet? Register   Sign In
DMZ Issues
#1

[eluser]Unknown[/eluser]
I seem to have trouble getting DMZ to work. Either I'm missing something obvious, or I'm just plain doing it wrong. I can't seem to get relationships to work. The tables don't join. What am I doing wrong here?

Datamapper Config (config/datamapper.php)
Code:
$config['auto_populate_has_many'] = TRUE;
$config['auto_populate_has_one'] = TRUE;

Blog Controller (controllers/blog.php)
Code:
public function index()
    {
        $latest = new Article();
        $latest->get();
        
        print_r($latest->all);
        
        $this->output->enable_profiler(TRUE);
        
    }

Articles Model (models/article.php)
Code:
class Article extends DataMapper
{
    public $table = 'articles';
    
    public $has_one = array('author');

    public function __construct($id = NULL)
    {
        parent::__construct($id);
    }
}

Author Model (models/author.php)
Code:
class Author extends DataMapper
{
    public $table = 'authors';

    public $has_many = array('article');
    
    public function __construct($id = NULL)
    {
        parent::__construct($id);
    }
    
}

Profiler Output
Code:
DATABASE:  personal   QUERIES: 2  
0.0129      SELECT * FROM `ci_articles` LIMIT 1
0.0011      SELECT * FROM (`ci_articles`)
#2

[eluser]David Cassidy[/eluser]
[quote author="harbingerkun" date="1264938208"]
Code:
public function index()
    {
        $latest = new Article();
        $latest->get();
        
        print_r($latest->all);
        
        $this->output->enable_profiler(TRUE);
        
    }
[/quote]

I believe the solution you are looking for is:
Code:
public function index()
    {
        $latest = new Article();
        $latest->include_related('author', '*', FALSE, FALSE);
        $latest->get();
        
        foreach($latest->all as $article)
        {
            print_r($article);
        }
        
        $this->output->enable_profiler(TRUE);
        
    }

If you check the source of the page, you'll see that the array does indeed include your author information.
#3

[eluser]santiagofs[/eluser]
I'm having a problem with the include_related function.
It works ok on my local server but its not getting the related objects on the online server.
Only difference I can see is the php version. I'm running v.5.2.5 locally and v.5.2.13 online.
Does anyone having a similar issue?

Thanks.




Theme © iAndrew 2016 - Forum software by © MyBB