ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

DMZ 1.7.1 (DataMapper OverZealous Edition)

March 14, 2010 11:43pm

Subscribe [104]
  • #226 / May 09, 2010 9:06pm

    OverZealous

    1030 posts

    I’m working on a major project and I’m building it from the ground up. I would like your advice if you have a minute… is there any authentication/user library/extension that you recommend for integrating with DMZ?

    Thank you for your positive feedback!  It’s very encouraging.  😊

    I don’t have an authentication library I use.  My application required fairly integrated auth functionality, so I rolled my own.  I based it on the original code from stensi that is still provided as an example in DMZ.  The example app uses the same basic mechanism for authorization.

    I don’t think anyone has yet created a dedicated extension to DMZ for authorization, so if you wanted to roll a generic one, that would be very appreciated.  😊

  • #227 / May 09, 2010 9:10pm

    Wible

    4 posts

    Maybe I’ll make that part of my mission. No reason why I can’t code it generic enough for others to use. I may contact you when/if I finish it. Anyway, I’m so psyched to see you’re an active participant in the community - the first two libraries I used were practically abandoned!

    Anyway… I think I’m going to take this on. I may approach you for feedback or advice if I run into snags.

  • #228 / May 10, 2010 4:47am

    jparent

    31 posts

    Hi, I don’t know if this question is solved, but I can’t find the answere anywhere. When I use datamapper object in my apps and I want to show a query as a table I can’t do somethink like:

    $data = $dtmpper_obj->get()->all;
    show_data_as_table($data);

    I can’t do that because in the table appears not only the data that I obtain in the select. Appears other fields of DataMapper main object, like prefixes, relationships,...

    any solutions? Thanks!

  • #229 / May 10, 2010 7:52am

    Alface

    41 posts

    Hi, I don’t know if this question is solved, but I can’t find the answere anywhere. When I use datamapper object in my apps and I want to show a query as a table I can’t do somethink like:

    $data = $dtmpper_obj->get()->all;
    show_data_as_table($data);

    I can’t do that because in the table appears not only the data that I obtain in the select. Appears other fields of DataMapper main object, like prefixes, relationships,...

    any solutions? Thanks!

    You have 3 way to solve it..

    Transfer the values to array before:

    $array = array();
    $dtmpper_obj->get();
    foreach($dtmpper_obj->all as $value){
        $data[] = $value;
    }
    show_data_as_table($data);

    Sending your DMZ objet to your helper(function) and execute the same foreach there:

    $dtmpper_obj->get();
    show_data_as_table($dtmpper);


    Or you can create a method on your DMZ class and call it like this (best way for me):

    $dtmpper_obj->get();
    $dtmpper_obj->show_data_as_table();
  • #230 / May 10, 2010 4:52pm

    introvert

    83 posts

    I want to update “updated” field when I update the relationship objects.
    DM OZ seems not to do that, although I set updated to “” (updated = “”) and call save(); function.

    As you noted, updated only changes when the object itself has changed.  There’s no supported way to change this behavior.

    One possible way, though, is to create an extra database column (like an int), and then override the save() function to increment this column whenever save() is called with an object.

    Or maybe someone has a better idea.  😊

    Can you include function update_timestamps in next version?

    Would be cool so that we can use custom call as well.

  • #231 / May 10, 2010 5:01pm

    OverZealous

    1030 posts

    @introvert
    I don’t know how hard it will be, but I’ll look into it.  I might have to rewrite save() so that if the updated field has been manually changed, then the object will save even if nothing else has changed.

  • #232 / May 10, 2010 7:16pm

    introvert

    83 posts

    Why wont this work:

    public function update_timestamp() {<br /> $timestamp = $this->_get_generated_timestamp();<br /> <br /> // Check if object has an 'updated' field<br /> if (in_array($this->updated_field, $this->fields))<br /> {<br /> // Update updated datetime<br /> $this->{$this->updated_field} = $timestamp;<br />       }<br />   }

    $object->update_timestamp();<br /> $object->save();

  • #233 / May 10, 2010 9:47pm

    OverZealous

    1030 posts

    @introvert

    Check out how the save() function works.  Currently, if the only changed field is the updated field, then it doesn’t bother saving.  (In fact, it rolls back the change to the updated field.)

    It’s a leftover decision from long ago.  I’ve actually thought about changing it, but it’s not a high priority thing.  Most people just use it the way it currently works, automagically.  😉

  • #234 / May 12, 2010 8:26am

    macigniter

    244 posts

    I got a question which I am sure was answered here before. But since the search function in this forum isn’t that great *duck* I am asking it here:

    Is there an easy way of detecting whether a dataset is related to any other table as defined in the models?

    Let’s say I have a “currencies” table with multiple rows:
    1 USD
    2 EUR
    ...

    Now before I allow to delete a currency I would like to check if that currency is somewhere related in any of the other tables (e.g. prices, invoices, etc.). Since all relations are stored in the models I am sure there is an easier way of doing this:

    $c = new Currency();
    $c->get_by_name(‘USD’);

    if ( ! $c->price->count() && ! $c->invoice->count() && ...) $c->delete();

    Something like $c->is_related() would be awesome. To check whether $c is related to any dataset in the related tables as defined in the models…

  • #235 / May 12, 2010 8:51am

    OverZealous

    1030 posts

    I got a question which I am sure was answered here before. But since the search function in this forum isn’t that great *duck* I am asking it here:

    Did you try the search in the manual?  It searches these forums as well.  It’s backed by Google™

    Is there an easy way of detecting whether a dataset is related to any other table as defined in the models?

    Why don’t you just write an extension.  All the relationships are stored in the $has_one and $has_many arrays.  Simply loop through the keys on those arrays, and do your count checks.  Note that is_related_to already exists, so it might be confusing to call it is_related.

    function is_related_to_anything($object) {
        $result = FALSE;
        foreach(array($object->has_one, $object->has_many) as $arr) {
            foreach($arr as $rel => $props) {
                $result = $object->{$rel}->count() > 0;
                if($result) {
                    break;
                }
            }
            if($result) {
                break;
            }
        }
        return $result;
    }

    Wrap that up in an extension, and you can share it with others, as well as use it on any model you want.

  • #236 / May 12, 2010 8:53am

    Wazzu

    27 posts

    Maybe “Query related models” topic may help you:
    http://www.overzealous.com/dmz/pages/getadvanced.html#_related
    So you can make a count() on it to ckeck if relation exist

  • #237 / May 12, 2010 8:57am

    macigniter

    244 posts

    Did you try the search in the manual?  It searches these forums as well.  It’s backed by Google™

    No. Thanks for the hint!

    Why don’t you just write an extension.  All the relationships are stored in the $has_one and $has_many arrays.  Simply loop through the keys on those arrays, and do your count checks.  Note that is_related_to already exists, so it might be confusing to call it is_related.

    Thanks, Phil. I’ll give that a try. You should get an award for always replying so fast… 😊

    EDIT: It rocks! Man how I love you for creating this amazing piece of code…

  • #238 / May 12, 2010 6:43pm

    leo_

    1 posts

    DMZ works really well for everything so far, and it’s been very useful.

    I have a question about the many-to-many relationship for the table setups though.  In the examples, http://overzealous.com/dmz/pages/relationtypes.html, there’s a skill_workers many-to-many relationship:

    skills_workers
    id   skill_id   worker_id

    Why does that table have its own ID? There’s no point to having duplicate data, so you might as well just set the primary key to the skill_id and worker_id.  Browsing through the DataMapper class, it seems to be ok with not having that extraneous id field, am I right in assuming that it’s not necessary?

  • #239 / May 12, 2010 10:21pm

    OverZealous

    1030 posts

    @leo_
    It is not necessary, but it is good database design.  Every table should have a unique, dedicated primary key.  For proper database normalization, it’s not usually recommended to use composite primary keys.  (I think at one time not all databases supported composite PKs, so having a dedicated PK also helped with portability.)

    As you noted, DMZ does not currently use the ID.  I still recommend it, and cannot guarantee that future versions of DMZ won’t use the ID.  There’s no good argument for leaving it out, IMO, because it’s a tiny integer field.

    Finally, a really good argument for it, is when having multiple relationships between the same objects (scroll to Setting up the Table Structure with Advanced Relationships).  In this case, there is more than just two columns on the table, and the PK is much less obvious.

  • #240 / May 13, 2010 12:51am

    tomdelonge

    60 posts

    I read real quickly about get_paged and get_paged_iterated. For some reason, get_paged() works fine. If I try get_paged_iterated() it gets screwed up. Wherever the loop was, nothing gets outputted. The rest of the page is outputs just fine, and as far as I can tell, no php errors are showing up.

    Any ideas on why it won’t work?

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases