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

[eluser]Unknown[/eluser]
I'm having an issue with DataMapper relationships. In the code below, focus on the $runobj->select_max... statement. After the query, this object is saved into $data["runquery"], which is loaded into the view.

Within the view I have a foreach statement that prints out the rows contained in $runobj. $runobj has a one-to-many relationship with $scriptobj, and I want to get an attribute of $scriptobj through $runobj, using $runobj->script->name (to get the name attribute of the script table, which is what $scriptobj is based off of).

This all works fine when using $runobj->get(), but when I include the select_max(), order_by(), group_by() statements, it doesn't seem to recognize the relationship. Any ideas why?

Code:
class Dashboard extends CI_Controller {
    public function index() {
        $scriptobj = new Script();
        $runobj = new Scriptrun();
        $serverobj = new Server();
        $runobj->select_max('date')->select('script_id')->
            group_by('script_id')->order_by('script_id')->get();
        //$data["sqlquery"] = $runobj->get_sql();
        $serverobj->get();
        $scriptobj->get();
        $data["runquery"] = $runobj;
        $data["scriptquery"] = $scriptobj;
        $data["serverquery"] = $serverobj;
        $this->load->view("dashboard_view", $data);
        
    }
}




Theme © iAndrew 2016 - Forum software by © MyBB