CodeIgniter Forums
[Deprecated] DMZ 1.5.3 (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: [Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) (/showthread.php?tid=18196)



[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 06-30-2009

[eluser]tdktank59[/eluser]
So is there a fix to make this work again???
Or do I need to go back to 1.3.1


[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 06-30-2009

[eluser]OverZealous[/eluser]
No, look at my post again, you need to update your search code to include the 'status_' before the table name, and everything will work again.


[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 07-01-2009

[eluser]tolyx[/eluser]
[quote author="OverZealous.com" date="1246430081"]@tolyx, bEz
Yes, the NULL requirement is by design and clearly explained in the documentation. (Thanks, bEz, for tracking this down!)
[/quote]

Okay thanks for clearing that up - this works now.

I now have another problem that I know you'll like. ;-)

When updating the work_example, I can't seem to save it like
Code:
$work_example->save();
- I have to save it with the portfolio again, a la
Code:
$work_example->save($portfolio);
otherwise it complains that the already-established 'portfolio relationship is required'.

Is this part of the design too?

Thanks!


[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 07-01-2009

[eluser]OverZealous[/eluser]
Are you reloading $work_example before saving it? Or at least setting the $id before saving it?

The _related_required validation routine works by counting the number of objects being saved, as well as counting the number of objects already stored in the database. It's not perfect — in fact, looking over the code, I realized that even the original DM version would overcount objects that were already saved in the database, but were getting saved again.

I did find a subtle bug in my version of the validation routine, but this would report a false positive, not a false negative.


[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 07-01-2009

[eluser]tdktank59[/eluser]
@OverZealous
Im back up and running thanks.


[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 07-01-2009

[eluser]MeanStudios[/eluser]
Phil (or anyone else), Self Relationships are still blowing my mind and I can't quite wrap my head around them ><. I have the following scenario:

Users - Each user has one Role

Roles - Each Role has many users. Also, each role only has one permission and parent role plus each parent role can have many roles under it.

Permissions - Each permission has one role.

Tables I have are:
users
- id
- role_id

roles
- id
- parent_id
- name

permissions
- id
- role_id
- data (holds permission data)

What I'm trying to do is setup the roles model and have it reference itself since a parent role can have many roles under it.

Help from anyone would be huge appreciated!


[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 07-01-2009

[eluser]MeanStudios[/eluser]
This is what I came up with...not sure if it will work:
Code:
class Role extends DataMapper
{
    var $has_many = array(
        'user',
        'child_role' => array(
            'class' => 'role',
            'other_field' => 'parent_role'
        )
    );
    
    var $has_one = array(
        'permission',
        'parent_role' => array(
            'class' => 'role',
            'other_field' => 'child_role'
        )
    );
    
    function Role()
    {
        parent::DataMapper();
    }
}
Table is:
roles
- id
- parent_role_id
- name


[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 07-01-2009

[eluser]OverZealous[/eluser]
You got it! I didn't have a chance to respond earlier, but that's exactly how I would have done it.

I don't know how often you are editing / looking up these relationships, but this might end up being query-intensive. Luckily you can use include_related to get items from the 'tree' 2 at a time.

Good Luck!


[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 07-02-2009

[eluser]tolyx[/eluser]
[quote author="OverZealous.com" date="1246478625"]Are you reloading $work_example before saving it? Or at least setting the $id before saving it? .[/quote]

Ah - I'm actually doing this in a loop. I guess I should use clear() on the object at the end of the iteration, right?


[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 07-02-2009

[eluser]OverZealous[/eluser]
The clear should probably help. I'm not 100% sure it's going to fix it, I've never looped over the same object during a save() — I tend to always load in new objects first.

DataMapper has two ways of working with objects during a save:

• If it is a new object (the id is empty()), then it saves every database column, unless it is NULL. NULL columns are not saved for new objects, to allow DB defaults to be set. (This is a big part of why in-table foreign keys need to be NULL.) The validation routine on runs over all columns on a new object.

• If it is an existing object (id is set), then it only saves the columns that have changed since the last get(). I believe that clear() also resets the changed columns list, but it won't load in the original column data, and it also clears the id. The validation routine runs almost the same, except it always runs over related fields, or fields that were empty() on the last get(). This means you will often get validation errors if the object is not properly loaded.

DataMapper tries to only go to the database when it is asked, selecting on get() and updating on save(). So it won't check to see if a column has changed.

I highly recommend performing a get_by_id() on any existing object you are going to save before you save it, so that DM can properly verify and validate the columns.