CodeIgniter Forums
DMZ 1.7.1 (DataMapper OverZealous Edition) - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: DMZ 1.7.1 (DataMapper OverZealous Edition) (/showthread.php?tid=28550)



DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 05-13-2010

[eluser]OverZealous[/eluser]
@tomdelonge

Are you still using the ->all array? You can't use that with get_paged_iterated. Check the examples on that page to see how you should loop over the object directly.

From 1.7 onward, the recommended way to iterate a DMZ result is to loop over the object directly (it will know what you want), and to get the number of results from a query is to use result_count().

(This is noted in the big yellow box on the get_iterated page.)


DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 05-13-2010

[eluser]Spir[/eluser]
I was wondering if I can do this :
Code:
$object->object->get_where(('field'=>'value'));

I have done this :
Code:
if ($object1->object2->get_where(('field'=>'value'))->count>0)
{
    foreach ($object1->object2 as $object2)
    {
        ...
    }
}
But the if pass even if no object2 are in the case of the filed requested.
But it doesn't loop on those element tho.

check_last_query says :
Code:
SELECT COUNT(*) AS `numrows`
FROM (`object2`)
WHERE `object1_id` = <id>



DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 05-13-2010

[eluser]OverZealous[/eluser]
@Spir
What are you trying to accomplish? You've said what you've done, but not what the goal is.


DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 05-13-2010

[eluser]tomdelonge[/eluser]
@OverZealous

I can't believe I missed that. Thanks, now it's working.


DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 05-13-2010

[eluser]Spir[/eluser]
[quote author="OverZealous" date="1273782934"]@Spir
What are you trying to accomplish? You've said what you've done, but not what the goal is.[/quote]I'm actually trying to filter on the relationship between object1 and object2.

Object1 has many Object2. I'm trying to get Object1's object2, and I only want to get specifi object2 that meet the filter I've set in get_where.

Also I could have done this:
Code:
$o1 = new Object1(123); // passing id

$o2 = new Object2();
$o2->where('field', $some_value);
$o2->where('object1_id', $o1->id)->get();

I would prefer to have a few line. And was thinking about this:
Code:
$object1 = new Object1(123);
$object1->object2->get_where(('field'=>'value'))



DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 05-13-2010

[eluser]OverZealous[/eluser]
@Spir
I just noticed you had ->count() at the end of your query. Check the manual: count() runs a different query!

The last query you wrote above would work. To see how many results, use result_count(). This is also in the manual.


DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 05-13-2010

[eluser]Spir[/eluser]
[quote author="OverZealous" date="1273789883"]@Spir
I just noticed you had ->count() at the end of your query. Check the manual: count() runs a different query!

The last query you wrote above would work. To see how many results, use result_count(). This is also in the manual.[/quote]My bad. Thanks for your time.


DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 05-13-2010

[eluser]Buso[/eluser]
I have this simple problem but I have no idea how to deal with it:

Im used to codeigniter's template parser, so I need my results in an array of arrays, so I can do something like:
Code:
{users}
User name:{name}
{/users}

What can I do about this? Datamapper results are arrays of objects.

I like objects, but cant use them in the templates. Do you know by chance an enhanced template parser which can deal with objects? Or a way to turn datamapper array of objects into array of arrays ?


DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 05-13-2010

[eluser]NachoF[/eluser]
Im trying to figure out what is the correct order of doing this when I want to save multiple things at the same time

For example.

I have Projects. Each project has many Phases. Each Phase has one State (Florida, Texas, etc)

In my form I have the data for a New Project as well as the FIRST phase of the given project so.

this definitely shouldnt work, right?

Code:
if($project->save(array($phase, $state)))
                    {
                            redirect("Success Screen");
                    }

How should I get this done?.. keep in my mind, Its ONE form so if something from validation fails it shouldnt save anything at all


DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 05-14-2010

[eluser]OverZealous[/eluser]
@Buso
Search for arrays in the manual. The first result is your answer. ;-)


NachoF
No, your example won't work, because $phase and $state would need to be saved separately. All new objects must be saved before the relationships are saved. After that, it doesn't matter what order things are saved in (it's the same number of queries). Smile

If you are saving multiple objects and/or multiple relationships, you should wrap everything in a transaction. (Auto transactions will not help.)