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]
  • #886 / Nov 26, 2011 5:09pm

    Daniel Peraza

    31 posts

    OK, thanks for your answer. Right now I’m doing some cool stuff with DataMapper ORM, but I have two questions about the form validation mechanism. First, repopulating my forms with set_value doesn’t seem to work as I was used to, what is the right way to do it? And second, I got a lot of “is_required” messages when the validation fails, why aren’t built-in CI’s language strings working? Right now I’m not using language files for my models as you describe in the user guide, but is that necessary in this case?

  • #887 / Nov 27, 2011 2:28pm

    WanWizard

    4475 posts

    Which CI version are you using? DataMapper is not compatible with the latest CI versions.

  • #888 / Nov 27, 2011 3:28pm

    Daniel Peraza

    31 posts

    I’m using 2.0.2, which was the latest compatible CI version?

  • #889 / Nov 28, 2011 7:46am

    adroit

    3 posts

    thanks for sharing pot on data mapper

    website designing services in mumbai

  • #890 / Nov 28, 2011 9:42am

    WanWizard

    4475 posts

    I’m using 2.0.2, which was the latest compatible CI version?

    DataMapper 1.8.1 works with 2.0.2, but with some glitches.

    Language is one of them. Because starting with CI 2.0 more and more core library properties and methods are declared protected or private, DataMapper no longer has access to them. So it loads it’s own version of the Language class, which does not have access to language strings loaded via $this->lang in your controllers ($this->lang in your model will work, as it will use DataMappers version).

    This is going to be rectified in DataMapper 2.0, which will use a new technique of accessing the core libraries.

  • #891 / Nov 29, 2011 12:29am

    Daniel Peraza

    31 posts

    Is there any workaround meanwhile?

    Please remember that repopulating my forms is very important.

  • #892 / Nov 29, 2011 2:07am

    WanWizard

    4475 posts

    DataMapper doesn’t do anything with repopulating forms, why would a repopulation issue be related to DataMapper?

  • #893 / Dec 04, 2011 4:26am

    Daniel Peraza

    31 posts

    As far as I have seen, DataMapper doesn’t run CI’ FormValidation rules by calling run(), it calls the rule function directly instead. This causes the FormValidation library not to store the _field_data array, which in turn, disables set_value() ability to repopulate the form.

    I’m not saying it’s wrong, I just want to find a workaround to deal with this.

  • #894 / Dec 04, 2011 4:54am

    WanWizard

    4475 posts

    DataMapper doesn’t do form validation at all.

    It does pre-save validation of object properties. And yes, some of the validation rules are borrowed from the form validation library. But that doesn’t mean it is the same as form validation.

    If you want to populate your forms from DataMapper objects, just use the object properties directly. If you need default values for new objects, add a method to your model that sets them when not exists(), and call that method before you load the view. Alternatively, you can call it from __construct() (and probably clear() as well) to do it automatically.

  • #895 / Dec 04, 2011 5:01am

    Daniel Peraza

    31 posts

    DataMapper doesn’t do form validation at all.

    That’s confusing, taking into account what says here: http://datamapper.wanwizard.eu/pages/validation.html

  • #896 / Dec 04, 2011 5:36am

    WanWizard

    4475 posts

    I don’t think that page says any different from what I just wrote, nor does it say it does something with forms.

    What exactly is confusing?

  • #897 / Dec 04, 2011 9:49pm

    Daniel Peraza

    31 posts

    You say that DataMapper doesn’t do any form validation at all, but the user guide says it does, so that’s confusing to me. Please explain a bit better (and thank you for your patience)

  • #898 / Dec 05, 2011 3:48am

    WanWizard

    4475 posts

    No, the user guide says that DataMapper provides object property validation.

    It runs validation rules on the object properties before you save the object (i.e. INSERT or UPDATE the record). It is not about POSTed variables at all, forms or form variables are not mentioned on that page.

    It only says that DataMapper is “borrowing some of the existing functionality from the CodeIgniter Form Validation library.” which means that for example DataMapper doesn’t provide it’s own valid_email() method, but instead calls the method in the form validation library.

  • #899 / Jul 06, 2012 7:55pm

    Jacob F.

    15 posts

    Hiya,

    I’m trying to use a deep relationship

    $groups->include_related('user/order',array('tweight','tprice'), TRUE)->get();


    These are legacy tables from before my time that I’m in the early stages of re-factoring (but can’t change them yet). The orders table has a different/nonsense name, there are no foreign key constraints, and the field-names where there should be foreign keys have non-DataMapper-friendly names (like `id_user`).

    The path from groups to users works fine (it’s new), but when jumping from users to orders, DataMapper is convinced there is a many-to-many relationship (it’s really one-to-many). I specified the following:

    #User
    
    $table = 'appuser';
    $has_many = array(
     'order' => array(
      'join_table' => 'oldorders',
      'join_self_as' => 'id_users'
     )
    );
    #Order
    
    $table = 'oldorders';
    $has_one = array(
     'user' => array(
      'join_table' => 'oldorders'
     )
    );

    I feel like it’s a hack to specify the join_table like that, but then DataMapper kind of accepts the one-to-many relationship: it eliminated the join for a relational table between users and orders, but it still uses the computed name of the non-existent relational table. Also, it doesn’t completely respect the join_self_as: it takes the value and appends it with _id.

    Here’s the SQL DataMapper spits out:

    #Without 'join_table'
    
    SELECT
     `groups`.*,
     `oldorders`.`tweight` AS appuser_order_tweight,
     `oldorders`.`tprice` AS appuser_order_tprice
     FROM (`groups`)
     LEFT OUTER JOIN `groups_appuser` groups_appuser
      ON `groups`.`id` = `groups_appuser`.`group_id`
     LEFT OUTER JOIN `appuser` appuser
      ON `appuser`.`id` = `groups_appuser`.`appuser_id`
     LEFT OUTER JOIN `oldorders_appuser` appuser_oldorders_appuser
      ON `appuser`.`id` = `appuser_oldorders_appuser`.`appuser_id`
     LEFT OUTER JOIN `oldorders` appuser_oldorders
      ON `appuser_oldorders`.`id` = `appuser_oldorders_appuser`.`id_appuser_id`
     ORDER BY `groups`.`name`;
    #With 'join_table'
    
    SELECT
     `groups`.*,
     `appuser_oldorders`.`tweight` AS appuser_order_tweight,
     `appuser_oldorders`.`tprice` AS appuser_order_tprice
     FROM (`groups`)
     LEFT OUTER JOIN `groups_appuser` groups_appuser
      ON `groups`.`id` = `groups_appuser`.`group_id`
     LEFT OUTER JOIN `appuser` appuser
      ON `appuser`.`id` = `groups_appuser`.`appuser_id`
     LEFT OUTER JOIN `oldorders` appuser_oldorders
      ON `appuser`.`id` = `appuser_oldorders`.`id_appuser_id`
     ORDER BY `groups`.`name`;
    #Correct SQL
    
    SELECT
     `groups`.*,
     `oldorders`.`tweight` AS order_tweight,
     `oldorders`.`tprice` AS order_tprice
     FROM (`groups`)
     LEFT OUTER JOIN `groups_appuser` groups_appuser
      ON `groups`.`id` = `groups_appuser`.`group_id`
     LEFT OUTER JOIN `appuser` appuser
      ON `appuser`.`id` = `groups_appuser`.`appuser_id`
     LEFT OUTER JOIN `oldorders` oldorders
      ON `appuser`.`id` = `oldorders`.`id_appusers`
     ORDER BY `groups`.`name`;

    EDIT: I tried changing both models to use $has_one and it spat out the same code. Also, it seems to ignore any declaring I do to user in the order model.

  • #900 / Jul 07, 2012 5:56am

    WanWizard

    4475 posts

    That will not work, all FK’s are suffixed with ‘_id’, hardcoded.

    I’ve looked at it, but it’s going to be very complex to change this, and changing this will break all existing applications that use this (and expect the suffix to be there).

    Changing this behaviour is on the roadmap for 2.0 (no ETA), but that doesn’t help you now.

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

ExpressionEngine News!

#eecms, #events, #releases