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]
  • #286 / May 24, 2010 10:19pm

    OverZealous

    1030 posts

    @Daniel H

    That error tells me that you are trying to save a thumbnail on the image object.  The image object can only accept a relationship of type event_thumbnail.

    Ex:

    // WRONG
    $image->save(array('thumbnail' => $event));
    
    // RIGHT
    $image->save(array('event_thumbnail' => $event));
    
    
    // WRONG
    $event->save(array('event_thumbnail' => $image));
    
    // RIGHT
    $event->save(array('thumbnail' => $image));
  • #287 / May 25, 2010 5:24am

    Daniel H

    197 posts

    Sigh - thanks so much Phil. Very tired eyes didn’t even spot that. Sorry to waste your time!

  • #288 / May 25, 2010 12:25pm

    Enorog

    13 posts

    Thank you Phil, I got everything working!

    The HMVC solution on the forums you mention is in regards to Modular Separation (the HMVC in that name is a mistake, it’s just a “organizing your modules” kind of library).

    I can report that DMZ works without problems with Modular Extensions for CI. It’s even nicer that way, because the only files in the regular CI models folder are DMZ classes, while you put the MVC models under MVC triads in /modules anyway.

    And the more I try DMZ, the more impressed I am. You should look at Doctrine one day just to feel better about yourself! 😊

    Jure

  • #289 / May 30, 2010 11:46am

    iancant

    7 posts

    Storing Additional Information on the Join Table

    Hi I am having some issues using DMZ. The documentation both online and in the download refers to this being possible, however don’t provide any suggestions or examples on how to do it.

    DataMapper DMZ: Advanced Relationships

    I know it may seem an odd request however large parts of my application require me to save an additional piece of information (ie. a number or string) along with the relationship.

    Also the colours on the page to help with explaining The Extended Relationship Attributes seem to have got out of sync.

    Thanks in advance.

    Ian

  • #290 / May 30, 2010 8:59pm

    OverZealous

    1030 posts

    @lancant

    See Working with Join Fields.

    The colors seem fine to me.

  • #291 / May 31, 2010 6:45am

    j0nxiest

    9 posts

    I didn’t quite get from the documentation how to work with related items with the from_array method. I tried to do like this:

    The form:

    <?php
    $usergroup = new Usergroup(); 
    $usergroup->where('group_name','user')->get(); 
    ?>
    <label for="username">Username: <input type="text" name="username" id="username" class="text" value="<?=set_value('username', $user->username); ?>" ></label><br>
    <input type="hidden" name="usergroup" value="<?=set_value('usergroup', $usergroup->id)?>" >

    The handler:

    $user = new User();
    $user->from_array($_POST);
    $user->save();

    But it complaints that the usergroup relation is not set, what am i doing wrong? The usergroup var is POSTed correctly.

  • #292 / May 31, 2010 6:53am

    Spir

    139 posts

    I didn’t quite get from the documentation how to work with related items with the from_array method. I tried to do like this:

    The form:

    <?php
    $usergroup = new Usergroup(); 
    $usergroup->where('group_name','user')->get(); 
    ?>
    <label for="username">Username: <input type="text" name="username" id="username" class="text" value="<?=set_value('username', $user->username); ?>" ></label><br>
    <input type="hidden" name="usergroup" value="<?=set_value('usergroup', $usergroup->id)?>" >

    The handler:

    $user = new User();
    $user->from_array($_POST);
    $user->save();

    But it complaints that the usergroup relation is not set, what am i doing wrong? The usergroup var is POSTed correctly.

    I’m not sure since I never used this and I discover this functionnality with your post but I think your solution is in the second parameter of the from_array function → from_array($data, $fields, $save)

    The field usergroup should be called usergroup_id?
    Why adding this hidden value if you won’t update it?
    http://www.overzealous.com/dmz/pages/extensions/array.html

    Also you could have specified TRUE then no need to call save().

  • #293 / May 31, 2010 11:45am

    Wazzu

    27 posts

    Count, group and field
    Hi all. I have a doubt trying to make a simple query with dmz:

    I want to make this query, so I get a 2 colums result, with the age and the number of users with that age: “SELECT age, count(age) FROM users GROUP BY age”

    But I don’t know how to use count() correctly with group.
    This won’t work:

    $u = new User();
    $u->select(‘age’);
    $u->group_by(‘age’);
    $u->count();

    How should I make this? Thanks in advance.

  • #294 / May 31, 2010 11:49am

    OverZealous

    1030 posts

    @Wazzu
    Count is not the same as SQL count.  It’s a special function that returns the number of results directly.

    I think to get what you want, you’ll need to use select_func():

    ...
    $u->select_func('COUNT', '@age', 'number');
    ...
    $u->get();
    echo $u->age;
    echo $u->number;

    Even if there was a function, it would be called select_count.  Please see the manual for the purpose of count.

    Update: Corrected typo - the method is select_func, not select_funct.

  • #295 / May 31, 2010 12:01pm

    Wazzu

    27 posts

    @Wazzu
    Count is not the same as SQL count.  It’s a special function that returns the number of results directly.

    I think to get what you want, you’ll need to use select_func():

    ...
    $u->select_funct('COUNT', '@age', 'number');
    ...
    $u->get();
    echo $u->age;
    echo $u->number;

    Even if there was a function, it would be called select_count.  Please see the manual for the purpose of count.

    Thanks, Phil, I’ll give a try. I didn’t know ‘select_funct’ method (I still haven’t found it in the user guide)

    The ‘other’ way I found was using 2 selects:

    $u->select('age');
    $u->select('count(age) as `numrows`');
    $u->group_by('age');
    $u->get();

    Thanks very much for your answer and your sample

  • #296 / May 31, 2010 12:02pm

    OverZealous

    1030 posts

    @Wazzu

    Ooops!  That’s supposed to be select_func - no ‘T’!!

    It’s under SQL Functions in the manual.

  • #297 / May 31, 2010 7:01pm

    Benedikt

    85 posts

    I have a small problem and I can’t think of what I am doing wrong (there must be something though):

    $u = new User();
    $u->get_by_id( 1 );
    
    $h = new House();
    $h->number = 9;
    $h->street = "Lonely Road";
    
    $h->save( $u );

    So far so good. If I now create a second house it will UPDATE the relationship between House and User instead if INSERT a new one.

    What am I doing wrong? Any idea?

  • #298 / May 31, 2010 10:22pm

    OverZealous

    1030 posts

    @Benedikt
    The second time you save the House, it’s already been saved, and therefore has an ID.  As far as DMZ is concerned, if you change the values, and save it again, it’s updating an existing object.

    Therefore, you have two options:

    • Either create a new House each time, or
    • Use the clear method to clear the values and prepare the house object to be saved as a new value.

    The difference is minor.  In theory, creating a new object should take more resources than clear it, but unless you are doing a large loop, the actual performance difference is probably close to zero.  I think it reads better to use new, because it is clearer what you are doing.

  • #299 / Jun 01, 2010 2:30am

    Benedikt

    85 posts

    Well, there is not a loop. By “create another one” I mean u fill out a form and click “Create”. Then a house is created.

    When I fill out the form again and create a new one it will create a new house but it will not add another relationship-entry. It will just update the existing relationship:

    “UPDATE jn_house_user SET user_id = 1 WHERE user_id = 1” or similar.

    I tried “$h->save_as_new( $u )” but it wont create a relationship, it will just create a new House-Object.

  • #300 / Jun 01, 2010 8:46am

    j0nxiest

    9 posts

    Hi,

    I’m having a problem with the transactions, can’t get them to work. I’m trying to do this:

    $user = new User();
    $user->username = $this->input->post('username');
    $user->trans_begin();
    $user->save();
    var_dump($user->trans_status()); // This is NULL, even though the validations fail
    if($user->trans_status() === false){
        $user->trans_rollback();
    }else {
        echo 'everything ok';
        $user->trans_commit();
    }
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases