ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

DataMapper 1.6.0

September 05, 2008 12:32pm

Subscribe [115]
  • #391 / Dec 20, 2008 6:20pm

    Emanuel01

    10 posts

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

  • #392 / Dec 21, 2008 12:12pm

    robertcsmith

    9 posts

    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:

    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.

  • #393 / Dec 28, 2008 7:19am

    Murodese

    53 posts

    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.

    snippet;

    class Auth
    {
        var $user = NULL;
        function __construct()
        {
            $this->obj =& get_instance();
            $this->obj->load->library('encrypt');
            
            $this->user = new User();
    
            $this->_load_session();
        }
  • #394 / Dec 28, 2008 5:43pm

    robertcsmith

    9 posts

    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.

  • #395 / Dec 29, 2008 4:45am

    ntheorist

    84 posts

    @robert

    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.

    @murodese

    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

  • #396 / Dec 29, 2008 7:04pm

    robertcsmith

    9 posts

    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

  • #397 / Dec 31, 2008 1:28am

    Murodese

    53 posts

    Having another issue;

    $obj = new $node->type();
                print_ar($obj->get_by_id($node->id)->$parent_type->get()->_to_array());

    $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:

  • #398 / Jan 02, 2009 6:52am

    Dreammaker

    30 posts

    @Murodese

    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 (http://ellislab.com/forums/viewthread/99274/) but if you’ll share the code I will not do it.

  • #399 / Jan 04, 2009 6:18am

    Murodese

    53 posts

    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.

    @Dreammaker:

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

  • #400 / Jan 04, 2009 1:37pm

    zool

    2 posts

    Hi,
    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.

    Btw…
    I have a very simple Model

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

    and a very very simple controller

    function index()
        {
            $u = new User();
            $u->username = 'Zool';
            if( $u->save() )
                echo "ok";
            else
                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?

  • #401 / Jan 05, 2009 9:06pm

    ntheorist

    84 posts

    @zool

    you need to set up validation in your model

    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

  • #402 / Jan 06, 2009 2:39am

    MirceaBotez

    3 posts

    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?

  • #403 / Jan 06, 2009 4:24pm

    BaRzO

    105 posts

    It’s happened Yesterday night you can download DM ( latest ) at first message all documents included in it

  • #404 / Jan 06, 2009 6:28pm

    stensi

    109 posts

    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.

  • #405 / Jan 14, 2009 6:19pm

    ntheorist

    84 posts

    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

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases