EllisLab text mark
Advanced Search
1 of 31
1
   
DataMapper ORM v1.8.1
Posted: 07 June 2011 03:37 PM   [ Ignore ]
Avatar
Joined: 2008-11-04
4404 posts

DataMapper ORM 1.8.1

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.

To install DataMapper ORM, 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.1:
  * New Features
      o Alternative model locations are supported through the model_path advanced relationship parameter, or through the add_model_path static method.
      o Added new truncate method to delete all records, and relations to those records.
      o You can now pass a string as parameter to the to_array() and all_to_array() methods of the array extension, if you want to select only a single field.
      o You can now run include_related on ‘many’ relations, see the docs for an explaination.
      o Added new force_validation() method to force revalidation when you read a record from the database that would not pass the save rules.
      o A new configuration value cascade_delete determines if delete operations need to cascade. See here.
      o Added support for the new CI reactor versions, in which Lang and Loader library properties are no longer public.
      o Added new where_between() methods to support “WHERE field BETWEEN a AND b” type queries.
      o The json extension now supports related objects, which will be exported as nested objects (‘id’ fields only).
  * Bug Fixes
      o Added support for a database prefix when specifying a join table (‘database.tablename’).
      o Extensions now receive the object that loads then as second parameter of the constructor, as documented.
      o Do not unnecessarily join tables in a many to many relationship when defining a where clause on the related ‘id’ field.
      o Fixed broken subqueries.
      o Fixed broken like() queries: missing trailing space and no automatic escaping.
      o Fixed nestedsets extension methods for moving sibling and child objects.
      o Fixed language error messages in the log due to undefined validation labels when using CI Reactor or CI 2.0.2.
      o Fixed incorrect SQL generated when using where() with a multi-value array just after a group_start().
      o Fixed broken query caching when using group_start().
  * Other Changes
      o Datamapper now checks if the CodeIgniter database library is loaded when the Datamapper class is instantiated, and exits with an error message if not.
      o The functionality of reciprocal self relationships is more clearly documented.

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.8.0, 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: 07 June 2011 04:37 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2011-03-26
109 posts

awesome, thanks for the update.

 Signature 

Ignited Datatables
Nested Sets

 
Posted: 08 June 2011 12:09 AM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Avatar
Joined: 2011-01-30
454 posts

Oh. My aching head. More stuff to remember.  tongue rolleye

 Signature 

This is the wonderful logo InsiteFX did for me. I had to scale it for this site. But his work is worth showing off.

 
Posted: 08 June 2011 03:29 AM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2008-11-04
4404 posts

Must be difficult for a basketcase…  LOL

 Signature 

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

 
Posted: 08 June 2011 06:35 AM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Joined: 2011-03-24
14 posts

For example I have a database where I have films and tapes related many to many, with a join field called frame_count which contains how many frames does the film have in specific tape.

Now I want to select sums of it for a list of both films and tapes where it would list like:

Film title | frame_count <- for films list

and

Tape title | frame_count <- for tape list

Atm I use some thing like:

$tapes->select('(select sum(`frame_count`) from `films_tapes` where `films_tapes`.`tape_id` = `tapes`.`id`) as frame_count'FALSE); 

I cant figure out any way of rewriting this in some subquery or other type of selection.

 
Posted: 08 June 2011 10:29 AM   [ Ignore ]   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2008-11-04
4404 posts

Easiest is to make a model for your relationship table. It doesn’t have to define any relations.

$films_tape = new Films_tape();
$films_tape->select_func('SUM''@frame_count''frame_count')->get(); 

If you want to access it via a relationship, you have to create a join using ‘include_join_fields’, which would add those fields to the select. You then have to come up with something clever to roll it all up into a single result, for example with a fake GROUP_BY.

Making join fields more accessable is definately something that needs to go onto the roadmap…

 Signature 

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

 
Posted: 08 June 2011 11:30 AM   [ Ignore ]   [ # 6 ]   [ Rating: 0 ]
Joined: 2011-04-11
20 posts

I’m having some trouble with the latest update and I’m hoping you can shed some light on the situation.  Here is a model-method I wrote that worked prior to the update:

/**
 * Selects entries with an appropriate publishing date range.
 * @return DataMapper Returns self for method chaining.
 */
public function published() {
    $now 
date('Y-m-d H:i:s');
    return 
$this->where('publish_start_date <='$now)
        ->
group_start()
            ->
where('publish_end_date IS NULL'// Published indefinitely OR...
            
->or_where('publish_end_date >='$now// Has not yet expired.
        
->group_end();

Following the update, wherever this method is called a fatal error is thrown: Call to a member function <whatever> on a non-object.  According to var_dump, the method is now returning NULL rather than an updated DM object.  What gives?

EDIT: for the record, I did wipe my production cache.

EDIT2: I suppose it’s also useful to note the fields’ datatype is datetime.

 
Posted: 08 June 2011 12:42 PM   [ Ignore ]   [ # 7 ]   [ Rating: 0 ]
Joined: 2011-04-11
20 posts

On further inspection, it appears this is an issue with any and *all* group_end() statements.

I took a look at group_end in the DataMapper library, and discovered this:

/**
 * Ends a query group.
 * @return    DataMapper Returns self for method chaining.
 */
public function group_end()
{
    $value 
str_repeat(' '$this->_group_count) . ')';
    
$this->db->ar_where[] $value;
    if(
$this->db->ar_caching$this->db->ar_cache_where[] $value;

    
$this->_where_group_started FALSE;

As you can see, *nothing* is being returned by the method.  I’m prepared to declare this a bug. smile

EDIT: the changeset responsible

 
Posted: 08 June 2011 01:35 PM   [ Ignore ]   [ # 8 ]   [ Rating: 0 ]
Avatar
Joined: 2008-11-04
4404 posts

Sorry for the late response, I’ve been hidding in a corner feeling very ashamed…  sick

Bug (and two more introduced in the same set of changes) have been fixed. Code on bitbucket, and the downloads, have been updated.

 Signature 

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

 
Posted: 08 June 2011 01:40 PM   [ Ignore ]   [ # 9 ]   [ Rating: 0 ]
Joined: 2011-04-11
20 posts

Just for clarification, you have now updated 1.8.1 with these fixes, correct?

 
Posted: 08 June 2011 01:44 PM   [ Ignore ]   [ # 10 ]   [ Rating: 0 ]
Avatar
Joined: 2008-11-04
4404 posts

Correct. Zips have been recreated, repository tag v1.8.1. has been moved up to include the fixes.

 Signature 

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

 
Posted: 08 June 2011 07:48 PM   [ Ignore ]   [ # 11 ]   [ Rating: 0 ]
Joined: 2010-11-05
7 posts

Question about deleting relationships.

I want to relate Object_A to many Object_B with a series of checkboxes. If it’s checked, make the relationship.

But when I want to edit the relationships I need a way of deleting the relationships, but leaving the object itself intact.

Is there an easier way than getting all the existing relationships, deleting them all, then going through the new list and creating the relationships again.


Thanks WanWizard for continuing the development of this awesome ORM!!

 
Posted: 09 June 2011 04:05 AM   [ Ignore ]   [ # 12 ]   [ Rating: 0 ]
Joined: 2011-05-30
18 posts

When i validate completely using my forms and i dont want to rewrite the same rules for my orm-model, how am i able to write data into the database?

My class:

class User extends DataMapper {
    
    
var $table 'user';
    var 
$has_one = array('group');
    
    var 
$validation = array();
    
    
/*
     * validates if given passwort belongs to user
     * @access public
     * @param $username string
     * @param $password string
     */
    
public function validate($username$password{
        $user 
$this->where('username'$username)->get();
        if(
$user{
            $userPassword 
$user->password;
            if(
sha1($password) == $userPassword{
                
return true;
            
}
        }
        
return false;
    

In the controller i do the following:

$userInput $this->add_user_form->post();

                
$newUser = new User();
                
$newUser->username $userInput->username;
                
$newUser->title $userInput->title;
                
$newUser->prename $userInput->prename;
                
$newUser->name $userInput->name;
                
$newUser->email $userInput->email;
                
$newUser->password sha1($userInput->password);
                
$newUser->group_id $userInput->group;

                
$newUser->skip_validation()->save(); 

I get the following error: You must use the “set” method to update an entry.

There is nothing inside the user table, which could be updatet. What is wrong?

PS: using v1.8.1

 
Posted: 09 June 2011 04:15 AM   [ Ignore ]   [ # 13 ]   [ Rating: 0 ]
Avatar
Joined: 2008-11-04
4404 posts

@Steve,

No, there isn’t. But you’ll have to retrieve the current relations anyway, to be able to prepopulate the checkboxes.
You can use that result to delete then as well.

 Signature 

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

 
Posted: 09 June 2011 04:21 AM   [ Ignore ]   [ # 14 ]   [ Rating: 0 ]
Joined: 2011-05-30
18 posts

My aim is to just write the validated form-values to the database without validating them again against the same rules.

Is this possible?

 
Posted: 09 June 2011 04:21 AM   [ Ignore ]   [ # 15 ]   [ Rating: 0 ]
Avatar
Joined: 2008-11-04
4404 posts

@benboi,

You haven’t defined any validation rules in your model, so no skip_validation() is needed.

The save() method does an UPDATE when $modelobject->id contains a value, and an INSERT if it’s NULL. Is this all your code, or are you assigning a value to the ‘id’ field somehwere?

The idea behind model validation is that you don’t have to do that in your controllers. No matter where in your application you update a model, the validation is run. If you do it in your controllers, you have to add validation code everywhere you’re updating the model.

Which will become a maintenance nightmare if your application has any size, and you add or change your table structure, you’ll have to scan your code to update all your controller-based validation code.

 Signature 

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

 
1 of 31
1