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.

[Deprecated] DMZ 1.6.2 (DataMapper OverZealous Edition)

November 23, 2009 11:54pm

Subscribe [46]
  • #196 / Jan 24, 2010 1:57am

    tdktank59

    322 posts

    It might not be in the docs, but usually it is something like this:

    $u = new User();
    $u->where_related_role('id', NULL);
    $u->get();

    Give it a shot, let me know if it doesn’t work for you.  You might have to play around with it, and look a the query generated.

    Duh… Didn’t click in my mind to use null in the related role…
    Was thinking more like where_not_in… separate train of thought.
    Thanks for the fix and it works btw!

  • #197 / Jan 24, 2010 5:58pm

    ocelot

    1 posts

    Hi Phil,

    First of all, great work, and great support.

    I just switched over to DMZ for a project, and now I’m getting some strange behavior re: escaping of SQL functions.  A bit of code using select_max() worked using DM but now is borked.  I saw your last post on this topic (http://ellislab.com/forums/viewreply/699007/) and tried to implement the $this->func(‘FUNCNAME’, ‘@columnname’), but with no luck.

    Here’s what I had at first, and the generated SQL:

    class Measurement extends DataMapper
    {
    ...
        function get_max_timestamp($unix_timestamp = TRUE)
        {
            $this->select_max('timestamp')->get();
            
            $this->load->helper('date');
            return $unix_timestamp ? mysql_to_unix($this->timestamp) : $this->timestamp;
        }
    }
    
    //SQL
    SELECT `MAX(`measurements`.`timestamp`)` AS timestamp FROM (`measurements`)
    
    //and got the error:
    Error Number: 1064
    
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`.`timestamp`)` AS timestamp FROM (`measurements`)' at line 1

    I changed the select_max() to use select_func() but get:

    $this->select_func('MAX', '@timestamp')->get();
    
    //SQL
    SELECT MAX() AS @timestamp FROM (`measurements`)

    I also tried:

    $this->select_func('MAX', 'timestamp')->get();
    
    //SQL
    SELECT MAX() AS timestamp FROM (`measurements`)

    and finally:

    $this->select_func('MAX(\'timestamp\')', 'timestamp')->get();
    
    //SQL
    SELECT MAX('timestamp')() AS timestamp FROM (`measurements`)

    I ended up just using:

    $this->select('MAX(`timestamp`)')->get();

    but this seems less than preferable.  Am I missing something obvious here?

    Thanks!
    Spike B

  • #198 / Jan 24, 2010 7:30pm

    OverZealous

    1030 posts

    @ocelot

    There’s nothing that should have changed between DM and DMZ regarding the select_XXX functions and field protection.  I just checked it, and the function works fine, both on Postgres and MySQL.

    Check the troubleshooting section of the manual, and verify the version of CodeIgniter you are using.

    Also, you are using the select_func method wrong.  Read the manual again - you must include a parameter to represent the alias:

    $this->select_func('MAX', '@timestamp', 'timestamp');
  • #199 / Jan 27, 2010 7:40am

    Alface

    41 posts

    I had been facing a problem for a long time with “HTML Form Generation Methods (htmlform) Extension”.
    The code is:

    class Company extends DataMapper {
        var $has_many = array(
                'telephone' => array(
                    'class' => 'telephone',
                       'other_field' => 'user'
                )
        );
        var $validation = array(
            'cname' => array(
                'label' => 'Company name',
                'type' => 'mult'
            ),
            'user' => array(
                'label' => 'Users'
            )
            );
    [...]
    }
    class User extends DataMapper {
        var $has_one = array(
                'user' => array(
                    'class' => 'user',
                       'other_field' => 'telephone'
                )
        );
        var $validation = array(
            'name' => array(
                'label' => 'Name',
                'rules' => array('trim')
            ),
            'email' => array(
                'label' => 'Email',
                'rules' => array('trim')
            )
        );
    
    [...]
    }

    The problem:
    I would like for it to instead of showing a drowdown for the itens from the database, show an input for the User ‘name’ and a button “More user”, and include another row of inputs.
    I know I will need a JS script, and I already have it. But I think I could use the render functions of htmlform Extension.

    Has anyone one been through this before?

  • #200 / Jan 27, 2010 3:31pm

    OverZealous

    1030 posts

    @Alface

    The HTMLForm extension has the ability to call any public method.  I believe it is in the docs under Custom Inputs.

  • #201 / Jan 27, 2010 4:05pm

    Alface

    41 posts

    I know that, but wouldn’t it be better and faster if the extension handled the creation of a form of relational models, don’t you think?

  • #202 / Jan 27, 2010 4:07pm

    OverZealous

    1030 posts

    @Alface

    The HTMLForm extension was originally designed more as an example extension.  I actually have stopped development on it, because I do not have time to support two complex projects.

    I was hoping to find someone to take over support of the extension, however the only interested party I had has not responded.

    I won’t be removing it, but I will not be adding any further features to the extension.

  • #203 / Jan 27, 2010 4:40pm

    Alface

    41 posts

    I’m working on it, do you think you would like to implement the modification on the original extension?
    Do you know somewhere I can find more extensions for DMZ?

  • #204 / Jan 27, 2010 4:45pm

    OverZealous

    1030 posts

    I appreciate the help, but I’m just not going to update the HTMLForm extension any more.  I’ll probably make a note in the manual that it is no longer supported as of the next release.  The HTMLForm extension has generated as much—if not more—problems and questions that the actual DMZ library.  :-(

    I had a comment about DMZ extensions earlier on this thread, trying to get others involved.

    The goal was to get others to add their extension to the DMZ Extensions category on the CodeIgniter wiki.

    You can search this thread or use the search in the DMZ manual (it searches all of the DMZ threads as well) to see at least a few others.

    Mainly, however, there really aren’t many out there with docs and links.

  • #205 / Jan 27, 2010 4:58pm

    Alface

    41 posts

    *I think that’s because the DMZ with HTMLForm extension became too much more powerfull..
    I understand what you mean about how I should search for extensions, but I don’t really know what I should search for to find a post related to what we just talked about..

    I think you should link the DMZ extensions wiki on manual or on fist post of this topic..

  • #206 / Jan 28, 2010 1:07pm

    Benedikt

    85 posts

    Hi,

    Does anybody have problems with the automated timestamps?

    When I create a new entry “updated” and “created” are filled with the same timestamp. But when I change one field of the entry the “updated” field is not changed.

    What could be wrong?

    $user = new User();
    $user->where('username', $this->input->post('username'));
    $user->update('password', $this->input->post('password'));

    I tried to use this coding inside the User-modell but it didnt work either.

    Any help?

    In the configuration I set globally
    $config[‘created_field’] = ‘_created’;
    $config[‘updated_field’] = ‘_updated’;

    Both fields exist (they are written on first save).

    Thanks for hints.

  • #207 / Jan 28, 2010 8:55pm

    OverZealous

    1030 posts

    @Benedikt
    The updated timestamp is not modified if no fields have been changed since the last get.  In other words, a row cannot be ‘touch’ed like a file through DMZ.

    Don’t forget to always check the generated queries when debugging.  If the above is true, you will not see an update query for the save.

  • #208 / Jan 29, 2010 2:38am

    Benedikt

    85 posts

    Thanks for your reply.

    So right before the update I need to perform a get?

    If yes, why is a get necessary to update the field updated? You could just always include the update field, at least as an option when calling update(). No?

  • #209 / Jan 29, 2010 2:50am

    OverZealous

    1030 posts

    @Benedikt

    No, you misunderstand me.  DMZ will never modify the update field unless something else has changed on the object.  In otherwords:

    $u = new User();
    $u->name = 'Bob';
    $u->save(); // created & updated fields changed
    
    $u->name = 'John';
    $u->save(); // updated field changed
    
    $u->save(); // Nothing happens
    
    $u2 = new User();
    $u2->where('name', 'John')->get();
    $u2->name = 'John';
    $u2->save(); // Nothing happens
    
    $u2->name = 'Fred';
    $u2->save(); // update field changed
    
    $u3 = new User();
    $u3->id = $u2->id;
    $u3->name = 'Fred';
    $u3->save(); // Update field *should* be changed, because DMZ sees u3 as an existing user whose name has changed from NULL to 'Fred'

    You should always get sometime before a Save, or else DMZ has no way of knowing which fields are changed or not.  (But not right before, or you lose your changes.)  This could lead to unnecessary writes in the DB, and a primary key GET should be several orders of magnitude faster than writing data to the database.

    In summary, the automatic update field is ONLY changed when there is a change in the object’s fields.  If you want something that changes on every save, even if nothing changed, I recommend creating a custom timestamp field and using the ‘always_validate’ rule and a custom validation rule to ensure that the field is updated every time.

  • #210 / Jan 30, 2010 5:49am

    Oblique

    32 posts

    count() problem

    sorry for so much complaining lately but i promise, if you’ll explain this i’ll post my extension, and some other code that someone might find usefull that is based on dmz in a couple of weeks )

    //There's case of using count() like the one in guide, but it generates strange query
    $client->freightage->where('status', self::$$status )->count();

    Unknown column ‘freightages.status’ in ‘where clause’

    SELECT COUNT(*) AS `numrows` FROM (`freightages_user_profiles`) WHERE ( `freightages`.`status` = 3 ) AND `user_profile_id` = 12

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

ExpressionEngine News!

#eecms, #events, #releases