Welcome Guest, Not a member yet? Register   Sign In
ActiveRecord for CodeIgniter: Rails-style model interactions
#62

[eluser]KJSDFHASD78FASDF78SA[/eluser]
@Andre83:
This reminded me of the new query modifier I planned to add a few days ago: fetching_related_*(). Which did the following.
Code:
$women = $this->woman->fetching_related_men('man')->find_all();

foreach ( $women as $woman )
{
    echo $woman->name . ' relates to ';

    foreach ( $woman->men as $man )
        echo $man->name . ', ';

    echo "\n";
}

However, this method increased the memory foot print of the script. So I ditched the idea altogether.

If one aims for speed it is ALWAYS better to fetch_related_*() for each object
returned by find_all(), rather than store ALL of them in the result array. E.g.

Code:
$women = $this->woman->find_all();

foreach ( $women as $woman )
{
    echo $woman->name . ' relates to ';

    foreach ( $woman->fetch_related_men('man') as $man )
        echo $man->name . ', ';

    echo "\n";
}

@ralf57: good ;-)


Messages In This Thread
ActiveRecord for CodeIgniter: Rails-style model interactions - by El Forum - 11-15-2007, 07:06 AM



Theme © iAndrew 2016 - Forum software by © MyBB