CodeIgniter Forums
DataMapper 1.6.0 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: DataMapper 1.6.0 (/showthread.php?tid=11358)



DataMapper 1.6.0 - El Forum - 01-05-2009

[eluser]ntheorist[/eluser]
@zool

you need to set up validation in your model
Code:
class User extends DataMapper {
    
    var $validation = array(
           'username' => array(
                'field' => 'username',
                'label' => 'Username',
                'rules' => array('required')
            ),
            'password'=> array(
                'field' => 'password',
                'label' => 'Password',
                'rules' => array('required')
            )
    )

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

}
and the errors will be generated if the callbacks in 'rules' fail. of course, it is very minimal and typically you'd run 'unique' on the username also, as well as min_length max_length on both.

hope that helps.

CC


DataMapper 1.6.0 - El Forum - 01-06-2009

[eluser]MirceaBotez[/eluser]
Anyone know what happened to stensi.com ?
Datamapper docs seem to be gone from there...

And while I'm here: has anyone tried DM with multiple (2) databases?
If so, can you please share how?


DataMapper 1.6.0 - El Forum - 01-06-2009

[eluser]BaRzO[/eluser]
It's happened Yesterday night you can download DM ( latest ) at first message all documents included in it


DataMapper 1.6.0 - El Forum - 01-06-2009

[eluser]stensi[/eluser]
Sorry guys. I'm in the middle of moving servers at the moment so as BaRzO mentioned, the latest DM version can be downloaded via the Source Files link in the first post (or my sig) or from the DM page in the CI Wiki. For convenience, here's the download link again:

DataMapper 1.6.0

The transfer is taking up a lot of my time so I haven't had a chance to fully catch up on the snazzy stuff commandercool's been doing.

@MirceaBotez: gusa posted a while back how he'd modifed DM to allow the ability for defining which database group a model can use. View the details here:

http://ellislab.com/forums/viewreply/478198/

Note that there will be issues if any of the related tables are on separate databases. For example, if you have a User model on Database A and a Group model on Database B, with the joining table on either, it will fail to work properly. Basically, you'll want to have all related tables on the same database.


DataMapper 1.6.0 - El Forum - 01-14-2009

[eluser]ntheorist[/eluser]
hey i'm playing with the idea of expanding DM again to include abstract data fields in the relationship tables (or at least allow for it to be applied)..

So, instead of having just the relationship table such as a table 'groups_users' with the fields [id, user_id, group_id], you could add fields such as [id, user_id, group_id, sort_order, member_status, join_date, etc..]

i figure since the three primary fields are there (id user_id group_id), everything should work as normal, but you'd be able to pull out relationship-specific information, or even search based on relationship data. For instance, i have an Album model and a Photo model, and i want to be able to sort the photos within an album and store that information, but the tables themselves shouldn't have relationship data in them (either case this would be terribly inefficient to manage)

anyone have any feedback on this idear?

CC


DataMapper 1.6.0 - El Forum - 01-20-2009

[eluser]tdktank59[/eluser]
UPDATE: Found the problem... The controllers name was the same as the models... Problem fixed now.

Im having an issue with the get function

Error Message:
Code:
[20-Jan-2009 14:35:03] PHP Fatal error:  Call to undefined method Brainstorm::get() in /home/fourtwo1/public_html/dirt/application/controllers/brainstorm.php on line 18

Controller
Code:
class Brainstorm extends Controller {

    function Brainstorm()
    {
        parent::Controller();
    }

    function index()
    {

    }

    function grid()
    {
        $b = New Brainstorm();
        $b->get();
        //$b->user->get();
        //$b->data_source->get();
        //$b->issue_type->get();
        //$b->status->get();
       // $b->priority->get();

        foreach ($b->all as $bstorm)
        {
            echo pre_print_r($bstorm);
        }

    }
}

/* End of file brainstorm.php */
/* Location: ./system/application/controllers/brainstorm.php */

Model
Code:
<?php

/**
* Brainstorm Class
*
* Transforms users table into an object.
* This is just here for use with the example in the Controllers.
*
* @licence     MIT Licence
* @category    Models
* @author      Simon Stenhouse
* @link        http://stensi.com
*/
class Brainstorm extends DataMapper
{
    var $table = 'brainstorms';

    //var $has_one = array("user", "status", "priority", "issue_type");
    //var $has_many = array("data_source");

    var $validation = array(
        array(
            'field' => 'title',
            'label' => 'Title',
            'rules' => array('trim', 'unique', 'min_length' => 2, 'max_length' => 255, 'alpha_dash')
        ),
        array(
            'field' => 'description',
            'label' => 'Description',
            'rules' => array('trim', 'alpha_dash')
        ),
        array(
            'field' => 'orgin_date',
            'label' => 'Orgin Date',
            'rules' => array('required', 'trim', 'is_natural')
        ),
        array(
            'field' => 'estimated_count_total',
            'label' => 'Estimated Count Total',
            'rules' => array('trim', 'is_natural')
        ),
        array(
            'field' => 'estimated_count_total',
            'label' => 'Estimated Count Manual',
            'rules' => array('trim', 'is_natural')
        )
    );

    /**
     * Constructor
     *
     * Initialize DataMapper.
     */
    function Brainstorm()
    {
        parent::DataMapper();
    }

    // --------------------------------------------------------------------

}

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

datamapper is being autoloaded


DataMapper 1.6.0 - El Forum - 01-21-2009

[eluser]Unknown[/eluser]
hi all.

just playing around with the datamapper today and revealing how powerful it is. it will be a great tool to further increase the speed of developing apps.

I wanted to create a helper to determine the current position within the returned array in a foreach loop.

I can return the total array elements fine "count(Object->all)" but I can't seem to get hold of the numeric key for each array.

Has anyone done this before and could perhaps provide some pointers.

thanks.


DataMapper 1.6.0 - El Forum - 01-22-2009

[eluser]ntheorist[/eluser]
@expo

have you tried $keys = array_keys($obj->all); ?

you can also access the keys with a foreach
Code:
foreach($obj->all as $key => $row){
     echo $key,' : ',$row->name,br();
}

CC


DataMapper 1.6.0 - El Forum - 01-22-2009

[eluser]wolffc[/eluser]
Is it possible to give an order column to the joining table? Lets say a user can pick 3 of 10 options and set a specific order. Would they be inserted and retrived in the same order?


Thanks


DataMapper 1.6.0 - El Forum - 01-22-2009

[eluser]tdktank59[/eluser]
So im having a problem saving a relationship...

For some reason no error shows up even tho it is failing... and on top of that its inserting the brainstorm but not the user relation...

I have removed the forms and stuff its just the datamapper stuff, Everything is being passed properly too

So let me know if you have any ideas...

Also all variables defined that are not show do exist...

Controller Code
Code:
$b = New Brainstorm();
$b->title                     = set_value('title');
$b->description               = set_value('description');
$b->orgin_date                = mktime(0,0,0,$date[0],$date[1],$date[2]);;
$b->estimated_count_total     = set_value('estimated_count_total');
$b->estimated_count_manual    = set_value('estimated_count_manual');
$u = New User();
$u->where('id',set_value('created_by'))->get();
if ($b->save($u))
{
$data['success'] = 'Brainstorm Created';
}
else
{
$data['error'] = $b->error->string;
}

brainstorm model
Code:
var $table = 'brainstorms';

var $has_one = array("user", "status", "priority", "issue_type");
var $has_many = array("data_source");

var $validation = array(
array(
'field' => 'title',
'label' => 'Title',
'rules' => array('trim', 'unique', 'min_length' => 2, 'max_length' => 255)
),
array(
'field' => 'description',
'label' => 'Description',
'rules' => array('trim')
),
array(
'field' => 'orgin_date',
'label' => 'Orgin Date',
'rules' => array('required', 'trim', 'is_natural')
),
array(
'field' => 'estimated_count_total',
'label' => 'Estimated Count Total',
'rules' => array('trim', 'is_natural')
),
array(
'field' => 'estimated_count_manual',
'label' => 'Estimated Count Manual',
'rules' => array('trim', 'is_natural')
),
array(
'field' => 'user',
'label' => 'User',
'rules' => array('trim', 'required')
)
);

User Model
Code:
var $has_many = array("brainstorm");

var $validation = array(
array(
'field' => 'username',
'label' => 'Username',
'rules' => array('trim', 'unique', 'strtolower', 'min_length' => 2, 'max_length' => 20)
),
array(
'field' => 'password',
'label' => 'Password',
'rules' => array('required', 'trim', 'min_length' => 3, 'max_length' => 40, 'encrypt')
),
array(
'field' => 'email',
'label' => 'Email Address',
'rules' => array('required', 'trim', 'strtolower', 'unique', 'valid_email')
),
array(
'field' => 'first_name',
'label' => 'First Name',
'rules' => array('required', 'trim')
),
array(
'field' => 'last_name',
'label' => 'Last Name',
'rules' => array('required', 'trim')
)
);