CodeIgniter Forums
DataMapper 1.6.0 - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived Libraries & Helpers (
+--- Thread: DataMapper 1.6.0 (/showthread.php?tid=11358)

DataMapper 1.6.0 - El Forum - 12-20-2008

Good work , thx .
I like the validation system with the rules in arrays .

DataMapper 1.6.0 - El Forum - 12-21-2008

Great stuff CC! This is a fantastic and elegant solution for those of us in the same boat.

Testing it now...

is get_array() on line 3498 (my personal fav).. is it needed or was it just a test?

so far this is my only thought:
[quote author="commandercool" date="1229703334"]
I'm not going to post every one of the added vars, functions and changes I made, plus this is still a work in progress, so i'll just attach the DataMapper file i've got so far and let anyone who wants to play with it, do just that.
when everything is ironed out perhaps consider offering this as an extended base class for DM rather than the need to replace all the code.

DataMapper 1.6.0 - El Forum - 12-28-2008

Having a problem that's more generally CI load-order related.

Auth library has a member object User (which is a DataMapper model), but is throwing "Class 'User' not found" errors when I try to instantiate it in the library's constructor. Both are being autoloaded, with Datamapper coming before Auth.


class Auth
    var $user = NULL;
    function __construct()
        $this->obj =& get_instance();
        $this->user = new User();


DataMapper 1.6.0 - El Forum - 12-28-2008

Hey CC, have you made any changes to your mod lately? Ive found an error while running validate() and get() to populate an instance of a class with $has_many classes.
A Database Error Occurred

Error Number: 1054

Unknown column '{$has_many_class}_count' in 'where clause'

Where {$has_many_class} is the the actual name of the has many class(es).

I haven't delved into debugging the error, but believe it is rooted in the _to_array() function. I thought Id check to see if you had made any upgrades before checking into it further. I can post or email more specific information if you need it too.

DataMapper 1.6.0 - El Forum - 12-29-2008


What were you trying to do when you got the error? can you post your controller code?
The aliasing feature works well for orderby and parsing results, but aliases can't be used in a WHERE clause, it seems.. i made a where_count function using group_by(id) and having, which seems to work, so i'll test that method out more

Ok i ported all the stuff i'm working on to a class that extends DM 1.6, and has the join stuff in it plus some new functions i'm playing with. Heh, yeah the get_array() thing is when i intend to over-ride, or just trying another name. I have a few added get_{how} methods there.

also, modified validation so you can validate and test specific fields:
$obj->validate_field($field) // validate specific field/relation
$obj->is_valid($field) // TRUE if field/relation is valid
$obj->is_valid() // TRUE if all fields/relations are valid
$obj->validate() // Validate all fields - same use as DM
been doing work with a form library for DM, so you'll see some of that in there, and some of it is probably still needed, lol

i'm thinking of changing adding a few more things, ie. to saving methods. Anyway its all in the works. Let me know what you think if you try it out.


other than verifying all the class names are correct, and user.php exists in the models/ directory, all i can suggest now is try changing 'function __construct()' to function Classname(), not sure but maybe that's something CI specific when loading

DataMapper 1.6.0 - El Forum - 12-29-2008

The error I encountered seems to have occurred due to 'continue' being used outside of a loop to escape the current statements... not sure if this is correct but changing the 'continue' on line 1064 to the following seems to solve the validation problem I was having:
$this->valid_fields[] = $field;
return $this;

*Edit: I mean line 1033 - I forgot I added something when I was playing around

DataMapper 1.6.0 - El Forum - 12-30-2008

Having another issue;

$obj = new $node->type();

$node->type holds the name of a model-class (this is correct).

$parent_type holds the name of the parent model (this is also correct).

However, I'm getting an object back with no data in the fields. The first object (client) exists and comes up fine, and the database has data linked correctly.

It's a self-referencing relationship though, which I assume is where it's causing trouble. I am totally at wits end with this however, it's worked properly for all other models I've been using, but it's having problems with this self-referenced one.

e; nevermind I'd forgotten to change a model variable :gonk:

DataMapper 1.6.0 - El Forum - 01-02-2009


Do you plan to share your crud generator? Or you develop this stuff for personal needs? I planed to implement DataMapper in Crud Generator for CI ( but if you'll share the code I will not do it.

DataMapper 1.6.0 - El Forum - 01-04-2009

Another note, just ran into a situation where having auto_transaction on completely stopped insert_id from working, leaving any objects with an id of 0 after saving.


It's pretty tailored to our own system, but if I get time I'll clean it up a bit and post it.

DataMapper 1.6.0 - El Forum - 01-04-2009

I don't know if it's the right place to post this issue because I don't know if it's a datamapper specific problem or a sqlite3 problem.

I have a very simple Model
class User extends DataMapper {
    function User()

and a very very simple controller
function index()
        $u = new User();
        $u->username = 'Zool';
        if( $u->save() )
            echo "ok";
            echo $u->error->string;
The table users in the db has three fields (id, username, password) all mandatory (the id is autoincremental)

With the code posted above I have an error.
The page breaks on $u->save() because I don't provide all the fields required (the password). But why the code breaks without entering in the else statement. If I set also the password all is working fine.

Someone has a similar problem? Or know a possible solution about it?