EllisLab text mark
Advanced Search
1 of 63
1
   
DataMapper ORM v1.8.2
Posted: 01 December 2011 11:59 AM   [ Ignore ]   [ # 11 ]   [ Rating: 0 ]
Avatar
Joined: 2008-09-17
90 posts
WanWizard - 01 December 2011 10:00 AM

Just change the protected to public. I’ll fix this tonight.

I changed. Now the error is:

Fatal errorCall to protected method CI_DB_active_record::_reset_select() from context 'DataMapper' in... 
 
Posted: 01 December 2011 03:01 PM   [ Ignore ]   [ # 12 ]   [ Rating: 0 ]
Avatar
Joined: 2008-09-17
90 posts

Array Extension performance

I have a doubt about to use extensions, in the case, the array extension. For example, I have a relative complex ->get() to work with this results.

If I use ->all_to_array(), all the after programming will take less resources of the server or is the same thing? And if the ->get() is more simple? If exists any performance variations, depends of the complexity of the generated query?

Regards!

 
Posted: 01 December 2011 04:29 PM   [ Ignore ]   [ # 13 ]   [ Rating: 0 ]
Avatar
Joined: 2008-11-04
4405 posts
tarciozemel - 01 December 2011 11:59 AM
WanWizard - 01 December 2011 10:00 AM

Just change the protected to public. I’ll fix this tonight.

I changed. Now the error is:

Fatal errorCall to protected method CI_DB_active_record::_reset_select() from context 'DataMapper' in... 

Found it. Will fix that too…

 Signature 

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

 
Posted: 01 December 2011 04:31 PM   [ Ignore ]   [ # 14 ]   [ Rating: 0 ]
Avatar
Joined: 2008-11-04
4405 posts
tarciozemel - 01 December 2011 03:01 PM

Array Extension performance

I have a doubt about to use extensions, in the case, the array extension. For example, I have a relative complex ->get() to work with this results.

If I use ->all_to_array(), all the after programming will take less resources of the server or is the same thing? And if the ->get() is more simple? If exists any performance variations, depends of the complexity of the generated query?

Regards!

All the array method does is iterate over the object, and copy the object properties to an array.

It has no relation whatsoever with the complexity of your query. If your query runs for 10 minutes, but only produces one result, all_to_array() will return an array with one element in a few milliseconds.

 Signature 

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

 
Posted: 01 December 2011 04:43 PM   [ Ignore ]   [ # 15 ]   [ Rating: 0 ]
Avatar
Joined: 2008-11-04
4405 posts

I have updated the online version of the 1.8.2 zipfiles, with fixes for the errors above, and one reported on the issue tracker (related to loading the form validation library).

 Signature 

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

 
Posted: 02 December 2011 02:01 PM   [ Ignore ]   [ # 16 ]   [ Rating: 0 ]
Avatar
Joined: 2008-10-15
147 posts

Hi,
I’m here again with my many to many relationship noobs question.
What is the best way to load join field when iterating on items.
Here are the models :

class Items extends DataMapper {
    
public $has_many = array(
        
'lang' => array(
            
'class' => 'lang',
            
'other_field' => 'item',
            
'join_self_as' => 'item',
            
'join_other_as' => 'lang'would be 'lang_id'
            'join_table' 
=> 'items_langs'
 
),
    );
class Langs extends DataMapper {
    
public $has_many = array(
        
'item' => array(
            
'class' => 'item',
            
'other_field' => 'lang',
            
'join_self_as' => 'lang',
            
'join_other_as' => 'item'would be 'item_id'
            'join_table' 
=> 'items_langs'
 
),
    );


Now I’m loading all items and looping on them. I want to display their data and the field “name” which is a data in the joined field (ie. in the table items_langs).

I have loaded my current language and I want to display the name of the item in my language. What is the best way to do it?

$items = new Item();
$items->get();

foreach(
$items as $item)
{
    $item
->lang->where('id'$default_language->id)->include_join_fields()->get();
    echo 
$item->lang->join_name;
    
// Would be nice to pass related field as param like this :
    
$item->include_join_fields($default_language)->get();

Lang is already loaded why loading it again? Any better solution?

 
Posted: 02 December 2011 08:47 PM   [ Ignore ]   [ # 17 ]   [ Rating: 0 ]
Avatar
Joined: 2008-11-04
4405 posts

A loop like this runs N+1 queries, which is probably not a good idea.

I would suggest getting them all in one go with something like:

$items = new Item();
$items->include_related('lang')->where_related_lang('id'$default_language->id)->include_join_fields()->get(); 

I don’t get why you say that lang was already loaded. I don’t see any code in your snippet that does this twice.

 Signature 

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

 
Posted: 02 December 2011 10:11 PM   [ Ignore ]   [ # 18 ]   [ Rating: 0 ]
Joined: 2011-07-14
1 posts

Update for The Example Code

Hey, i’m new to ORM, and this is the first ORM i’ve ever learned. I’ve read The DataMapper Manual and it suggested me to try the Example Project which you provided, but unfortunately the code seems not compatible with the latest CI. I’m using CI 2.1.0 and DataMapper 1.8.2.
I’m sorry for asking this, and i know you must be very busy too, but when will the example code get an update?

 
Posted: 03 December 2011 06:08 AM   [ Ignore ]   [ # 19 ]   [ Rating: 0 ]
Avatar
Joined: 2008-11-04
4405 posts

The example code hasn’t been looked at since CI 1.7.1. I’m afraid.

Bringing it up to date is on my todo list, which unfortunately is quite long. I can see if there is a quick fix for the current example application, but I will probably rewrite the example application for DataMapper v2.

 Signature 

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

 
Posted: 03 December 2011 07:25 AM   [ Ignore ]   [ # 20 ]   [ Rating: 0 ]
Avatar
Joined: 2008-10-15
147 posts
WanWizard - 02 December 2011 08:47 PM

A loop like this runs N+1 queries, which is probably not a good idea.

I would suggest getting them all in one go with something like:

$items = new Item();
$items->include_related('lang')->where_related_lang('id'$default_language->id)->include_join_fields()->get(); 

I don’t get why you say that lang was already loaded. I don’t see any code in your snippet that does this twice.

I load the lang based on user in parent controller (MY_Controller).
Thanks WanWizard.

 
Posted: 03 December 2011 03:34 PM   [ Ignore ]   [ # 21 ]   [ Rating: 0 ]
Avatar
Joined: 2008-11-04
4405 posts

@azheem,

I’ve updated the example application, and added some quick fixes to the htmlform extension to make it work.

The 1.8.2 download has been updated with these fixes, download it again if you want to try the example.

 Signature 

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

 
Posted: 04 December 2011 10:38 PM   [ Ignore ]   [ # 22 ]   [ Rating: 0 ]
Avatar
Joined: 2010-05-13
8 posts

Hi i found some error after try to using example application on codeigniter 2.1.0 and datamapper 1.8.2

Fatal errorCall to undefined method CI_DB_mysql_driver::dm_call_method() in C:\wamp\www\examples\application\libraries\datamapper.php on line 1113 
 
Posted: 05 December 2011 04:49 AM   [ Ignore ]   [ # 23 ]   [ Rating: 0 ]
Avatar
Joined: 2008-11-04
4405 posts

Then you haven’t read the docs, and didn’t install the bootstrap in your index.php file.

This is new since 1.8.2, see http://datamapper.wanwizard.eu/pages/installation.html

 Signature 

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

 
Posted: 05 December 2011 09:49 PM   [ Ignore ]   [ # 24 ]   [ Rating: 0 ]
Joined: 2011-12-05
1 posts

Same error occur:
Fatal error: Call to undefined method CI_DB_mysql_driver::dm_call_method() in C:\wamp\www\examples\application\libraries\datamapper.php on line 1113

Any work fine version with full packaged code base include CI 2.1.0 and DataMapper1.8.2 ?
We will be greatly appreciated!

 
Posted: 05 December 2011 11:10 PM   [ Ignore ]   [ # 25 ]   [ Rating: 0 ]
Joined: 2009-11-15
26 posts

You need to add

/*
 * --------------------------------------------------------------------
 * LOAD THE DATAMAPPER BOOTSTRAP FILE
 * -------------------------------------------------------------------- *
 */
require_once APPPATH.'third_party/datamapper/bootstrap.php'

directly before the

/*
 * --------------------------------------------------------------------
 * LOAD THE BOOTSTRAP FILE
 * --------------------------------------------------------------------
 *
 * And away we go...
 *
 */
require_once BASEPATH.'core/CodeIgniter.php'

in your index.php

 
1 of 63
1