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]
  • #136 / Dec 28, 2009 10:26pm

    OverZealous

    1030 posts

    @Michael Ditto

    Very slick.  That’s a great example of a validation extension.

    Don’t forget you can (and should) require the extension this way:

    class User extends DataMapper {
        // User needs the require_at_least validation extension
        var $extensions = array('require_at_least');
        ...

    This should work without issue, and keeps you from having to override the constructor unnecessarily.

  • #137 / Dec 28, 2009 10:51pm

    janus303

    10 posts

    @Michael Ditto

    Very slick.  That’s a great example of a validation extension.

    Don’t forget you can (and should) require the extension this way:

    class User extends DataMapper {
        // User needs the require_at_least validation extension
        var $extensions = array('require_at_least');
        ...

    This should work without issue, and keeps you from having to override the constructor unnecessarily.

    Ahh! Done. I completely missed that convention.

  • #138 / Dec 29, 2009 2:09am

    Cro_Crx

    247 posts

    Anyway, thanks (very much) to Cro_Crx for providing such a clear test case and making it so easy to track down!

    Thanks for fixing it so quickly. I went to bed just after posting that, when I woke up this morning it was already fixed 😊

  • #139 / Dec 29, 2009 2:21am

    Cro_Crx

    247 posts

    I’ve just downloaded the latest copy. Seems to be working well. Although up the top it’s showing the wrong version in the comments:

    * @version     1.6.1 ($Rev: 292 $) (Based on DataMapper 1.6.0)
  • #140 / Dec 29, 2009 2:26am

    OverZealous

    1030 posts

    Doh!  Thanks for catching that.

    Stupid complex update routine…

    Edit: OK, the download has the updated version number!

  • #141 / Dec 30, 2009 2:28pm

    cube1893

    18 posts

    Hi,

    I’m experiencing performance problems with the following code, which is located in a view:

    foreach($course->get()->all as $course)
    {
      foreach($course->application->get()->all as $application)
      {
         $application->applicant->get();
    
         [..........]
         echo $application->applicant->name;
         echo $course->name;
     
      }
    }

    As there are many courses and many applications related to each course, the last query (getting the applicants) results in approx. 380 single database queries. That’s very bad and the page loads very slow.
    Is it possible to combine the calls of get in one query in order to have one single database query for the code snippet above?

    A course has many applications, aapplication has one applicant.

    I’d appreciate any help!
    Daniel

  • #142 / Dec 30, 2009 2:32pm

    OverZealous

    1030 posts

    @cube1893
    See Include Related.

    Also, limit the fields you need to access with select statements.  Don’t load every column if you don’t need every column.

    Finally, you should be paging with over 300 items.  That shouldn’t be causing a slowdown, but sometimes the performance problems are in your design, not the library.

  • #143 / Dec 30, 2009 3:04pm

    cube1893

    18 posts

    @OverZealous

    Thanks, include_related helps but it only works for one-to-one relationships (applicant). How can I achieve the same for one-to-many relationships? For example if I want to access all “note” objects for an application in the second foreach loop. If I call $applicationg->notes->get() in every loop, it causes bad performance, again.

  • #144 / Dec 30, 2009 5:37pm

    OverZealous

    1030 posts

    There’s no way to solve that - even for normal SQL queries.  Again, you have a design problem, the performance issue is that you are trying to query so many objects at once.

    There was an earlier post that had info on an extension for streaming the results so you don’t have to instantiate all objects at once.

  • #145 / Dec 30, 2009 5:43pm

    tdktank59

    322 posts

    So I am trying to drag some join fields in
    Found the include_related_fields() function
    Just to make sure im using it right here is how I use it

    $u = new User();
    $u->get_by_id($id);
    $u->role->include_join_fields()->get();

    However it is not bringing the fields over like it should be.
    $u->role->join_start_on and $u->role->join_end_on

    the fields are start_on and end_on
    Every part of the relation still works just having issues dragging those values into the query.

    Auto populate has_one and has_many are set to TRUE since most pages I use require most if not all of the relationships any object can have.

  • #146 / Dec 30, 2009 6:44pm

    tdktank59

    322 posts

    Thanks for the language files, Muser and tdktank59.  I’ve added them to the distribution.

    If anyone else out there would like to provide localized error messages, I would be very appreciative!

    Out of curiosity, what naming structure would you prefer for the language folders:

    1) Use the English names for the languages:

    catalan/
    english/
    spanish/

    2) Use the native names for the languages (in unaccented ASCII characters):

    catala/
    english/
    espanol/

    3) Use the ISO-639-1 2-letter codes:

    ca/
    english/ (for CI compatibility)
    es/

    Personally, I prefer #3 whenever possible.  In fact, if I ever localize my application, I would be tempted to use an RFC 5646 structure like this:

    ca/
    en/
    en-US/
    en-GB/
    es/
    es-ES/
    es-MX/
    ...

    Doesn’t really matter.
    As far as CI is concered i dont think it cares besides the english folder.
    However I like method 3 since It would allow more variations and what not. However would be nice if it was spelled out fully instead of shortened.

    I currently am using english translations of everything since i am well english. It really all comes down to how much do you want to support. I can see Method 3 being usefull if you have multiple devs with diffrent languages being used. However method 2 can pose some problems when you get to eastern languages with the “hieroglyphics” (not sure on the term) such as Hebrew, Chinese, Japanese etc… since those are standard UTF characters.

    It all comes down to user preference, and the amount of people that will have to maintain the back-end, and where they are all from.

    I personally wont be working with other developers who do not know english so I can keep it in English on the back end. As long as the end user sees the translated result in their language.

  • #147 / Dec 30, 2009 6:57pm

    OverZealous

    1030 posts

    I’ve already decided, due to the limited feedback, to use the last format, except regional formats are <lang>_<region> (underscore not dash).

    The purpose of the shortened names is simply to standardize, and the linked ISO/RFC standard is the only one I know of that takes into account regional dialects.

    Anyway, the provided languages are already included in the most recent update.

  • #148 / Dec 31, 2009 1:15am

    tdktank59

    322 posts

    Yeah that works I guess…

    So I feel really stupid on the join include issue… Turns out the values where null..
    And I had typed them wrong…

  • #149 / Jan 02, 2010 8:43pm

    rootman

    7 posts

    I’m having some trouble with the unique_pair validation. It seems not to work when saving relationships.

    in my model (in validation array):

    'email' => array(
                'label' => 'Email',
                'rules' => array('required', 'trim', 'unique_pair' => 'gewinnspiel_id', 'valid_email')
            ),

    “gewinnspiel_id” is a has_many to has_one relationship

    I save my model like that:

    $gewinnspiel_antwort->save($gewinnspiel);

    And it saves doublicates, same email, same relationship ... should not validate but does.

    I guess it adds the relationship after saving to the db, so it does not have the id to do the unique_pair check when saving.

    The workaround is to add the relationship manually:

    $gewinnspiel_antwort->gewinnspiel_id = $gewinnspiel->id;

    and then just save it.

    But i guess it would be nice if the validation would work without the workaround ... but maybe the saving process is designed in a way which would make it very tricky to solve that due to saving relationships after saving the data.

    And btw, great work, i am using dmz about three days now and it already saved my life a dozen times!

    greetings

  • #150 / Jan 03, 2010 12:28pm

    silvergear99

    7 posts

    Ok, so I have like this.
    Models

    class User extends DataMapper 
    {
        
        var $has_one = array('group','contact','user');
    
        var $validation = array
        (
            'username' => array
            (
                'label' => 'Username',
                
                'rules' => array('trim', 'required', 'unique', 'min_length' => 4, 'max_lenght' => 50)
            )
        );
        
        
        function __construct($id = NULL)
        {
            parent::__construct($id);
        }
        
        function __toString() 
        {
            return $this->username;
          }
    }
    
    class Contact extends Datamapper
    {
        
        var $has_one = array('user');
        
        var $validation = array
        (
            'name' => array
            (
                'label' => 'Full name',
                'rules' => array('trim','required', 'min_length' => 5, 'max_length' => 255)
            )
        );
        
        function __construct($id = NULL)
        {
            parent::__construct($id);
        }
        
        function __toString()
        {
            return $this->name;
        }
    }
    
    class Group extends Datamapper
    {
        var $has_many = array('user');
        var $validation = array
        (
            'name' => array
            (
                'label' => 'Name',
                'type' => 'dropdown',
                'rules' => array('required')
            )
        );
        
        function __construct($id = NULL)
        {
            parent::__construct($id);
        }
        
        function __toString() 
        {
            return $this->name;
          }
    }

    view

    echo $user->render_form
    (
        array
        (
            'username',
            'group' => array
            (
                'label' => 'Group',
                'type' => 'dropdown'
            ),
            'contact_name' => array
            (
                'label' => 'Full name',
                'type' => 'text'
            ) 
        ),
        "admin/users/edit/{$user->id}",
        array
        (
            'save_button' => 'Change'
        )
    );

    Controller User

    function edit($id = NULL) 
        {
            $user = new User();
            $user->where('id',$id);
            $user->include_related('contact',array('name'));
            $user->get();
            
            if($this->input->post('username'))
            {
                $related = $user->from_array($_POST, array('username','group','contact_name')); 
                $user->save($related);
            }
            
            $data['main_content'] = 'admin/users/edit_view.php';
            $data['user'] = $user;
            $this->load->view('admin/template.php', $data);
        }

    Everything saves except contact_name. Im not getting any errors. Any tips ?

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

ExpressionEngine News!

#eecms, #events, #releases