EllisLab text mark
Advanced Search
1 of 38
1
   
DataMapper ORM v1.8.0
Posted: 12 January 2011 06:17 PM   [ Ignore ]
Avatar
Joined: 2008-11-04
4420 posts

DataMapper ORM 1.8.0

Download the Latest Version Here

  View the change log and the upgrade process
  Having issues? Please look through the Troubleshooting Guide & FAQs
  View the Complete Manual
  Search the Manual
  (Due to the server’s caching configuration, you may need to forcibly refresh your browser to see the changes in the manual.)

DataMapper (DM) is an Object-Relational Mapper that builds on ActiveRecord.  Data is loaded from database tables into objects, and relationships can be managed through simple, easy-to-read functions.

DataMapper ORM adds several important features to DM(Z), further enhancing it’s usage, usually without requiring any code changes.

To install DataMapper ORM over DMZ, the (fairly simple) upgrade process is described here.

DataMapper offers these features:
  • Everything is an object!
  • Easy to setup, easy to use.
  • Custom Validation on object properties.
  • Lazy Loading (related objects are only loaded upon access).
  • Relations and their integrity are automatically managed for you.
  • One to One, One to Many, and Many to Many relations fully supported.
  • Select data in the style of Active Record (with or without Method Chaining).

You can learn much more from the manual.

—————

Version 1.8.0:
  * New Features
      o Added a new extension which allows you to use Datamapper for nested set tree management.
      o Added dutch language file.
      o Added a new extension which allows you to use Datamapper for nested set tree management.
      o It is now possible to define model relations, and update the model production cache, at runtime.
      o Updated the select() method to accept an array of column names next to a comma delimited string, like CodeIgniters Activerecord does.
      o The updated column can now be modified manually. The save method will save the update even if the updated timestamp is the only modified field.
      o The column name is now used as key of the error->all array, which allows you to reference the column name when iterating over the errors.
      o Added (experimental) support for reciprocal many-to-many relationships. See Advanced Relationships.
      o Added the option to define the name of the relationship table in an advanced relationship definition.
      o Added the option to run $object->{query}_related using a Datamapper object as $value. In case the object contains multiple values, the query will be transformed to a ‘where_in’ query using the id’s in the objects resultset.
      o >Added the option to run $object->{query}_related using an array of id’s. If the array contains multiple values, the query will be transformed to a ‘where_in’ query using the id’s in the objects resultset.
  * Bug Fixes
      o Fixed problem with get_iterated when using PHP 5.3+ which doesn’t do an implicit type conversion from array to object, causing an isset() to fail.
      o Fixed PHP fatal error when loading a model when using CI 2.0 packages or Modular CI, and a package or module is missing a models directory.
      o Fixed incorrect SQL count and SQL error on get_paged and get_paged_iterated when paging through a related table, linked to the parent using a relationship table, and including a where clause on a parent column.
      o Fixed race condition that could case a fatal error due to recursion when deleting ITFK’s.
  * Other Changes
      o All language files have been converted to UTF-8.
      o Replaced hardcoded check for the MY_ prefix with the ‘subclass_prefix’ config value when autoloading classes.
      o When using include_join_fields, the id field of the relationship table is included as well.
      o Added some info about the post_model_init method to the documentation.
      o The manual now makes it clear that there are several reasons for a save to fail and gives some examples of what to check.

Make sure to check out the changelog — you won’t want to skip this update!

—————

Bug reports and feature requests:

Please use the issue register / bug tracker on bitbucket to report new bugs or for new feature requests. If you do, please include in your description is link to the thread on this forum discussing the issue (if possible), so I have a link between the two and can keep track of all issues.

—————

Older Discussions: Version 1.7.1, Version 1.6.2, Version 1.5.4, Version 1.5.3 and older.

Thanks goes to Overzealous, for all he has achieved with DMZ. And to stensi, for providing such an amazing code base to work on.

 Signature 

Me: WanWizard.eu | My company: Exite | Datamapper: DataMapper ORM

 
Posted: 12 January 2011 06:49 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Joined: 2009-11-06
24 posts

Excellent, thanks!  The new nested sets library looks very promising for hierarchical data.

Thanks for your work on this, it wasn’t trivial.

 
Posted: 13 January 2011 05:41 AM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Joined: 2009-09-10
40 posts

Thank you very much! New version is awesome!

 
Posted: 13 January 2011 05:48 PM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Joined: 2010-10-11
15 posts

Hi,

I try using language lines for the validation, but I get the following error:

Parse error: syntax error, unexpected ‘(’, expecting ‘)’ in /var/www/virtual/beazy.org/htdocs/system/application/models/event.php on line 13

The language library and the helper are autoloaded and work fine everywhere else.

Anyone knows how to solve this?

Thx!

<?php

class Event extends DataMapper {
    
    
var $has_many = array('user');

    var 
$validation = array(
        array(
            
'field' => 'title',
            
'label' => lang('wording_title'),
            
'rules' => array('required'),
        ),
        array(
            
'field' => 'date',
            
'label' => lang('wording_date'),
            
'rules' => array('required'),
        )
    );

    function 
Event()
    
{
        parent
::DataMapper();
    
}
    
}

/* End of file event.php */
/* Location: ./application/models/event.php */ 
 
Posted: 14 January 2011 11:47 PM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Avatar
Joined: 2009-03-19
103 posts

Hey MAN !!!

GREAT NEWS !!! Thanks for keeping this project alive ! You really rock !!!

I will update my apps and see if everything runs smooth… Thank you SOOOO MUCCCHHHH!!!!!

 
Posted: 15 January 2011 07:39 AM   [ Ignore ]   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2008-11-04
4420 posts

@momsenmeister,

Are you sure? Afaik you can’t use function calls ( lang() ) for assignment in a class property definition. You can do

<?php

class Event extends DataMapper {
    
    
var $has_many = array('user');

    function 
Event()
    
{
        parent
::DataMapper();

        
$this->validation = array(
                array(
                    
'field' => 'title',
                    
'label' => lang('wording_title'),
                    
'rules' => array('required'),
                ),
                array(
                    
'field' => 'date',
                    
'label' => lang('wording_date'),
                    
'rules' => array('required'),
                )
            );
    
}
    
}

/* End of file event.php */
/* Location: ./application/models/event.php */ 
 Signature 

Me: WanWizard.eu | My company: Exite | Datamapper: DataMapper ORM

 
Posted: 15 January 2011 01:37 PM   [ Ignore ]   [ # 6 ]   [ Rating: 0 ]
Joined: 2011-01-15
1 posts

Hi, First of all I really like data-mapper. It is very well thought. I was trying to follow the user guide , i was on get advanced when I came across this:

// Get a list of all male users
$u = new User();
$u->where('gender''M')->get();

// Get all the messages these males have posted
$p = new Post();
$u->where_related('user''id'$u->all)->get(); 

In the second pair of lines, there is a $post instance , but it is not used in the sentence , I tried but don’t understand how to fix it. How would it be if it was fixed, of course there is an error here, but I can’t make sense of what is the point of this example.

Please help.

 
Posted: 15 January 2011 02:30 PM   [ Ignore ]   [ # 7 ]   [ Rating: 0 ]
Joined: 2010-10-09
14 posts

Should be $p->where_related…
posts are being filtered by all related users from the prior selection.

 
Posted: 15 January 2011 02:48 PM   [ Ignore ]   [ # 8 ]   [ Rating: 0 ]
Joined: 2010-10-09
14 posts

WanWizard, thanks for the new update & your great work on carrying this on!

And of course, I have a question wink

I’m using the HtmlForm extension to crank out new entry forms for a table, and it all works fine, including my related-field dropdowns.

But I’d like to pre-select a default choice on certain dropdowns for related fields, and I can’t figure out a way to do this. i.e.

Class Color extends DataMapper { [objects with value "red""green""blue"]}

Class Block {
   
var $validation = array(
    
'color' => array(
        
'rules' => array('is_natural'),
          
'type'=>'dropdown'
    
)...}
...
now I'd like to dynamically select 'green' as a default choice
...
then
$block->render_form($ff,'
controller'); 

Since it’s not a simple field, I can’t just set $block->color = ‘green’, and if I do:

$color = new Color();
$color->where('name','green')->get();
$block->save($color);
$block->render_form($ff,'controller'); 

This works, but leaves me with a ‘partial’ database entry (since the user hasn’t filled in the other $block fields). I don’t really want to commit this object to the database yet, just set the initial default for the dropdown list (my ‘real’ dropdowns could be really long lists).

Any help or hints much appreciated…

 
Posted: 15 January 2011 05:41 PM   [ Ignore ]   [ # 9 ]   [ Rating: 0 ]
Avatar
Joined: 2008-11-04
4420 posts
bachstein - 15 January 2011 06:37 PM

In the second pair of lines, there is a $post instance , but it is not used in the sentence , I tried but don’t understand how to fix it. How would it be if it was fixed, of course there is an error here, but I can’t make sense of what is the point of this example.

This looks like an error in the manual, I’ll have a look.
The error in the manual has been corrected.

 Signature 

Me: WanWizard.eu | My company: Exite | Datamapper: DataMapper ORM

 
Posted: 15 January 2011 06:07 PM   [ Ignore ]   [ # 10 ]   [ Rating: 0 ]
Avatar
Joined: 2008-11-04
4420 posts

@madwhistler,

I haven’t had a look at htmlform. It’s included but unsupported since Datamapper DMZ 1.7. I haven’t got a clue what it actually does…

 Signature 

Me: WanWizard.eu | My company: Exite | Datamapper: DataMapper ORM

 
Posted: 15 January 2011 10:46 PM   [ Ignore ]   [ # 11 ]   [ Rating: 0 ]
Joined: 2010-10-09
14 posts

Right-o. Htmlform is quite nice but a bit buggy, it’s an amazing prototyping time-saver to be able to whack out a screen form with a few extra validation lines and a single “build the form” call.

I’ve solved my problem, I think, with a front-end jQuery call to $(#myfieldid).val(selected-value). Simpler than trying to dig into the guts of htmlform, at least…

 
Posted: 18 January 2011 07:11 AM   [ Ignore ]   [ # 12 ]   [ Rating: 0 ]
Joined: 2010-10-11
15 posts

Hi,

trying to get started with DataMapper, I face a weird problem.

All I try to do is this in my controller:

$e = new Testy();
$e->get();
var_dump($e); 

But I end up with an endless output of pretty much all data that exists somewhere in my code igniter folders (including language files, config file with fully readable encryption key! and so on). How is that even possible to access these files?

This is the model:

<?php

class Testy extends DataMapper {

    
var $table 'event';
    
    
//var $has_many = array('user');
    //var $has_one = array('city');

    
function Testy()
    
{
        parent
::DataMapper();
        
        
$this->validation = array
        (
          array(
              
'field' => 'title',
              
'label' => lang('wording_title'),
              
'rules' => array('required'),
          ),
          array(
              
'field' => 'date',
              
'label' => lang('wording_date'),
              
'rules' => array('required'),
          ),
          array(
              
'field' => 'location_description',
              
'label' => lang('wording_location_description'),
              
'rules' => array('required'),
          ),
          array(
              
'field' => 'datetime',
              
'label' => lang('wording_datetime'),
              
'rules' => array('required'),
          )
        );
    
    
}
    
}

/* End of file testy.php */
/* Location: ./application/models/testy.php */ 

Any idea what I might be doing wrong?

 
Posted: 19 January 2011 11:05 AM   [ Ignore ]   [ # 13 ]   [ Rating: 0 ]
Avatar
Joined: 2008-06-25
30 posts

momsenmeister var_dump is just doing its job, Check out the docs

 Signature 

StuckTogetherWithTape

 
Posted: 19 January 2011 11:16 AM   [ Ignore ]   [ # 14 ]   [ Rating: 0 ]
Avatar
Joined: 2008-06-25
30 posts

I’m wondering what the best way is to save a new record to a large set of related records.

I want to save a new email record to all contacts it was sent to. The email could have thousands of recipients.

get_iterated() is great as it means i can load all these records from the db without running out of memory. However, this means i cant use:

$email->save($contacts->all); 

As the all array is not set for iterated objects. Is there a nice way I can save an object to an iterated related object, or should i stick to looping though the related items

$email->save();

foreach(
$contacts as $contact)
{
    $email
->save($contact);
 Signature 

StuckTogetherWithTape

 
Posted: 19 January 2011 06:07 PM   [ Ignore ]   [ # 15 ]   [ Rating: 0 ]
Joined: 2010-10-11
15 posts
The Hamburgler - 19 January 2011 04:05 PM

momsenmeister var_dump is just doing its job, Check out the docs

Thx a lot, my fault grin

But unfortunately, I have a new question:
set_value() doesn’t seem to work anymore?
I need it to repopulate my forms.

 
1 of 38
1