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.

DataMapper 1.6.0

September 05, 2008 12:32pm

Subscribe [115]
  • #961 / Jun 29, 2009 11:31pm

    PoetaWD

    97 posts

    I’m pretty sure it’s a bug in DMZ.  I’m doing some tests now, to see what’s going on.  It might take me a few minutes.

    Update: Yes, it is a bug.  I’ve got a fix in place, and will have an updated version of DMZ for download in about 10 minutes.  Thanks for finding this PoetaWD - it’s a very serious bug, but luckily had an easy fix!

    I am VERY happy that I helped… dont rush ... we want it flawless !

    DMZ rox !

    Thanks man !

  • #962 / Jun 29, 2009 11:32pm

    OverZealous

    1030 posts

    I just realized what forum we are on.  PoetaWD - moving to the DMZ forum, because this is a problem that is unique to DMZ.

  • #963 / Jun 30, 2009 12:01am

    PoetaWD

    97 posts

    I just realized what forum we are on.  PoetaWD - moving to the DMZ forum, because this is a problem that is unique to DMZ.

    ,

    Ow..

    That is true !

    Sorry for that! I will start posting there instead !

    Thanks

  • #964 / Jul 01, 2009 12:36pm

    gshipley

    6 posts

    Thanks again for the great ORM.

    Sorry if this is covered in the docs but I swear I couldn’t find it.  If it is, please just point me to the correct location in the doc.

    Question: get_by_related

    $u->get_by_related(‘group’, ‘name’, ‘Moderator’);

    What is I wanted to get_by_related where moderator is like ‘rat’


    $u->get_by_related(‘group’, ‘name’, ‘%rat%’;

    Is that supported? (I think the exact syntax above doesn’t work but is there a function call I am missing?)

  • #965 / Jul 01, 2009 12:42pm

    OverZealous

    1030 posts

    The get_by methods are just utility methods.

    You can’t do more complicated queries in one call, but it is easy to chain the methods like this:

    // like CI's ActiveRecord, the '%' are automatically added to the query.  See the Get page of the manual
    $u->like_related('group', 'name', 'rat')->get();
  • #966 / Jul 01, 2009 12:48pm

    gshipley

    6 posts

    The get_by methods are just utility methods.

    You can’t do more complicated queries in one call, but it is easy to chain the methods like this:

    // like CI's ActiveRecord, the '%' are automatically added to the query.  See the Get page of the manual
    $u->like_related('group', 'name', 'rat')->get();

    Perfect!  thank you so much.

  • #967 / Jul 02, 2009 6:37pm

    [x26]VOLAND

    5 posts

    Can I create several validation rule groups besides “var $validation = array(...);” ?

  • #968 / Jul 02, 2009 7:08pm

    ntheorist

    84 posts

    the quick and dirty way to skip validation:

    $user = new User();
    $user->last_login = time();
    $user->validated = TRUE; // fool into thinking its been validated
    $user->valid = TRUE; // set as valid
    $user->save();

    You could write entire new validation arrays and overwrite it, then run validate(), but Datamapper stores the validation array in a static variable for any new instance of that model. You’d have to hack the constructor to allow for more.

    better might be to build on top of DM, perhaps an extending class for your models, where you’d have your normal validation array, except each field could have a ‘group’ => $groupname var in it. (this would always either be specified, or set to a default group), then create a function such as validate_group($groupname)

    the point tho, as above, it all comes down to setting $this->validated and $this->valid to TRUE, but you really don’t want to skip validation altogether you’ll end up with a mess/overwriting data etc.

  • #969 / Jul 03, 2009 1:12am

    OverZealous

    1030 posts

    Can I create several validation rule groups besides “var $validation = array(...);” ?

    I’m unsure what you are asking here.  DataMapper only supports one set of validation rules.

    There are two ways you can change the validation rules on-the-fly, however:

    1) If you need a simple change based on an obvious factor, write your own validation rule.  This rule could then check to see if it needs to be checked, and process the rule appropriately.

    2) If you need massive validation changes, you can actually just replace $object->validation on the object you want to validate, and that will be used.  Alternatively, you could replace a part of $validation, but this will affect all models of that type for that HTTP request, because they share a single validation array.

  • #970 / Jul 03, 2009 5:56pm

    ntheorist

    84 posts

    it sounds like he wants to employ two uses of a single model. With the typical user model this would mean he prolly wants to be able to bypass creating a login (required for user) to store just an identity or for tracking. One idea would be to create a base Person model that ‘User’ extends, with little or no validation, or another way may be to create an extending model using a self join and give that a name with its own validation, ie:

    class Temp_User extends User {
    
         $model = 'temp_user';
         $table = 'users';
    
         $validation = array( 
              // only validate lastlogin etc
         }
    
         function Temp_User()
         {
              parent::User();
         }
    
    }

    in the case with the user model, you’d want to have some way to prevent empty logins. If you have your login() function in the User model, you overwrite it in Temp_User.

    n

  • #971 / Jul 05, 2009 7:04pm

    zovar

    30 posts

    Can someone explain me how to use additional variables while saving relationships with dataMapper?

    I have 3 tables: users, projects, projects_users. I am assigning users to projects. But I also have an option to make user a manager for the project. How to handle this? Should I create table managers_projects? Or maybe there is a way to add ‘is_mananger’ field into projects_users?

    This is just an example. Usually I create additional tables and custom functions to handle the data. But this is very time consuming.

    Any help?

  • #972 / Jul 05, 2009 7:50pm

    OverZealous

    1030 posts

    Please see the DataMapper OverZealous Addition for an updated version of DM that supports options like that without having extra tables.
    The forum link is in my sig, as well as a documentation link.

    The feature you want to look at is Working With Join Fields. You can easily add an is_manager column to your join table, and set, read, and query it.

  • #973 / Jul 05, 2009 8:12pm

    zovar

    30 posts

    Thank you, this is a very useful addition!

  • #974 / Jul 06, 2009 4:14pm

    gshipley

    6 posts

    Hey guys—its your favorite noob again.

    I have the following statement:

    $usermovies = $tmpUser->usermovie->like_related_movie(‘title’, $title)->get();

    I was wondering if/how I can order these results based on a field (title) in the related table?

    ie:
    $usermovies = $tmpUser->usermovie->like_related_movie(‘title’, $title)->order_by(‘title’)->get();

  • #975 / Jul 06, 2009 7:27pm

    OverZealous

    1030 posts

    I’m not able to check this, but you should simply try:

    $tmpUser->usermovie->like_related_movie('title', $title)->order_by_related_movie('title')->get();

    I think the code is smart enough to make that work.

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

ExpressionEngine News!

#eecms, #events, #releases