EllisLab text mark
Advanced Search
26 of 31
26
   
DataMapper ORM v1.8.1
Posted: 19 December 2011 02:37 PM   [ # 381 ]   [ Rating: 0 ]
Avatar
Joined: 2008-09-17
90 posts

John Murowaniecki,

Something like that, but in group_by() cheese

 
Posted: 19 December 2011 02:43 PM   [ # 382 ]   [ Rating: 0 ]
Avatar
Joined: 2011-08-03
85 posts

Holy Noodle! I think I read that wrong, anyway I was wrong..

..Wait.

 Signature 

http://john.manydevs.com
.—-—- .... -. /—..- .-.—- .—.- -. .. . -.-. -.- ..

 
Posted: 19 December 2011 02:44 PM   [ # 383 ]   [ Rating: 0 ]
Avatar
Joined: 2008-11-04
4489 posts
tarciozemel - 19 December 2011 01:47 PM

In the ->group_by() section of the DataMapper user guide, the syntax is wrong.

Will be corrected at the next “push”...

 Signature 

Me: WanWizard.eu | My company: Exite | Datamapper: DataMapper ORM <= LOOKING FOR A NEW MAINTAINER!

 
Posted: 19 December 2011 02:46 PM   [ # 384 ]   [ Rating: 0 ]
Avatar
Joined: 2011-08-03
85 posts

..Instead of this:

/**
     * Group By
     *
     * Sets the GROUP BY portion of the query.
     *
     * @param    string $by Field to group by
     * @return    DataMapper Returns self for method chaining.
     */
    
public function group_by($by)
    
{
        $this
->db->group_by($this->add_table_name($by));

        
// For method chaining
        
return $this;
    

..use this:

/**
     * Group By
     *
     * Sets the GROUP BY portion of the query.
     *
     * @param    string or array $by Field to group by
     * @return    DataMapper Returns self for method chaining.
     */
    
public function group_by($by)
    
{
        
if ( ! is_array($by)) $by = array($by);
        
#
        
foreach ($by as $field)
        
{
            $this
->db->group_by($this->add_table_name($field));
        
}
        
# For method chaining
        
return $this;
    

On our lovely application/libraries/datamapper.php .

 Signature 

http://john.manydevs.com
.—-—- .... -. /—..- .-.—- .—.- -. .. . -.-. -.- ..

 
Posted: 19 December 2011 02:50 PM   [ # 385 ]   [ Rating: 0 ]
Avatar
Joined: 2008-09-17
90 posts

John Murowaniecki,

Nice solution to “our lovely application/libraries/datamapper.php”! haha LOL

I used this in an update in the core of Google Load library.

 
Posted: 19 December 2011 03:01 PM   [ # 386 ]   [ Rating: 0 ]
Avatar
Joined: 2011-08-03
85 posts
tarciozemel - 19 December 2011 02:50 PM

John Murowaniecki,

Nice solution to “our lovely application/libraries/datamapper.php”! haha LOL

I used this in an update in the core of Google Load library.

Shure your idea is better then mine, using if ( ! is_array($var)) $var = array($var); foreach ($var ... is much more clean and pretty wise.

/**
     * Group By
     *
     * Sets the GROUP BY portion of the query.
     *
     * @param    string or array $by Field to group by
     * @return    DataMapper Returns self for method chaining.
     */
    
public function group_by($by)
    
{
        
if ( ! is_array($by)) $by = array($by); # <--- as you suggested on Google LoadLibrary post
        #
        
foreach ($by as $field)
        
{
            $this
->db->group_by($this->add_table_name($field));
        
}

        
// For method chaining
        
return $this;
    

Google LoadGoogle Load Library

 Signature 

http://john.manydevs.com
.—-—- .... -. /—..- .-.—- .—.- -. .. . -.-. -.- ..

 
Posted: 19 December 2011 03:06 PM   [ # 387 ]   [ Rating: 0 ]
Avatar
Joined: 2008-09-17
90 posts

John Murowaniecki,

Very nice!  wink

 
Posted: 06 January 2012 05:33 AM   [ # 388 ]   [ Rating: 0 ]
Joined: 2012-01-06
2 posts

Hello Forum, Im new to the DataMapper ORM!

I would like to get some help setting up the DataMapper to 3 object/tables from TankAuth.
Or rather, i would love to get some explaining on how the works of DataMapper considering the correct thinking when setting up DataMapper against non standard DataMapper tables.

Ok so i got these three objects.. User, User_profile & Role.

In DB they have these fields as described below:

Users
—————-
id
username
password
email
role_id (holds the role id of user)
...

Roles
—————-
id
role
default

user_profiles
———————
id
user_id (holds the id of the user the specific profile refering to)
country
website

I know that this isnĀ“t standard DataMapper, what should u call it, definition, but its okey.

Now I would like to link these objects together with the help of DataMapper Advanced Relationships. (http://datamapper.wanwizard.eu/pages/advancedrelations.html)

This is my code so far, ive tried to fiddling around with the relationships for a few hours without any success…. as said im new to ORM and DataMapper..

class User_dm extends DataMapper {

        
var $has_one = array(
            
'role' => array(
                
'class' => 'Role_dm',
                
'join_self_as' => 'role_id'
                
),
            
'user_profile'
        
);

        var 
$table 'users';
        
        public function 
__construct($id NULL)
        
{
                parent
::__construct($id);
        
}

    } 
class Role_dm extends DataMapper {

        
var $has_many = array(
            
'user' => array(
                
'class' => 'User_dm',
                
'join_self_as' => 'id',
                
'join_other_as' => 'role_id'
                
)
        );

        var 
$table 'roles';

        public function 
__construct($id NULL)
        
{
                parent
::__construct($id);
        
}

    } 
class User_profile extends DataMapper {

        
var $has_one = array(
            
'user'
        
);

        public function 
__construct($id NULL)
        
{
                parent
::__construct($id);
        
}

    } 

Anybody that can help me out? would be much appreciated! or give me some explanation on the join criteras and how i should use them!

 
Posted: 06 January 2012 04:50 PM   [ # 389 ]   [ Rating: 0 ]
Avatar
Joined: 2008-11-04
4489 posts

Like in the examples in the manual, the “_id” suffix should not be defined, as Datamapper will append those automatically. Therefore, if your foreign key is called “role_id”, you should define it in the relationship as “role”.

 Signature 

Me: WanWizard.eu | My company: Exite | Datamapper: DataMapper ORM <= LOOKING FOR A NEW MAINTAINER!

 
Posted: 07 January 2012 09:27 AM   [ # 390 ]   [ Rating: 0 ]
Joined: 2012-01-06
2 posts

thank you, I finally got it to work with some help from this thread as well.. http://ellislab.com/forums/viewthread/190266/#921516

 
Posted: 10 January 2012 07:47 PM   [ # 391 ]   [ Rating: 0 ]
Avatar
Joined: 2010-07-28
7 posts

Quick question on validation, is there any point in doing form validation as well as object validation or is this double handling?

 
Posted: 11 January 2012 03:03 AM   [ # 392 ]   [ Rating: 0 ]
Avatar
Joined: 2008-11-04
4489 posts

As always, the answer is “that depends”.

I always use object validation. No matter where the data is coming from, it is validated before it goes into the database, so you can be sure the data is valid, and all required data is present. It also means that you do your validation in one place, instead of in every controller that might have an interaction with your model.

But sometimes you want to do other things with your form input then send it directly to the object to save it. Or you have forms with fields that don’t map to object properties. In which case form validation is the way to go.

Datamapper’s validation uses CI’s Form Validation library for most of it’s rules, so doing it in two places just runs the same checks twice.

 Signature 

Me: WanWizard.eu | My company: Exite | Datamapper: DataMapper ORM <= LOOKING FOR A NEW MAINTAINER!

 
Posted: 11 January 2012 07:49 PM   [ # 393 ]   [ Rating: 0 ]
Avatar
Joined: 2010-07-28
7 posts

Thanks, that is a great help!

Also, not sure if it is documented anywhere but i had the form_validation library auto-loading and this was causing a conflict with the ‘required’ rule on datamapper objects just saying that it couldn’t find the message.

 
Posted: 12 January 2012 02:44 AM   [ # 394 ]   [ Rating: 0 ]
Avatar
Joined: 2008-11-04
4489 posts

I would be interested to know the exact description of that conflict. Can you give the exact error messages?

Datamapper just loads the form validation library if not loaded, otherwise it will simply reuse it. It has done so for years, and should not cause any conflicts…

 Signature 

Me: WanWizard.eu | My company: Exite | Datamapper: DataMapper ORM <= LOOKING FOR A NEW MAINTAINER!

 
Posted: 12 January 2012 07:07 PM   [ # 395 ]   [ Rating: 0 ]
Avatar
Joined: 2010-07-28
7 posts

“Unable to access an error message corresponding to your rule name: required.”

Removing ‘form_validation’ from the array of auto loaded libraries below will fix this.

$autoload[‘libraries’] = array(‘database’, ‘datamapper’, ‘session’, ‘form_validation’);

 
26 of 31
26