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]
  • #661 / Mar 16, 2009 11:49am

    gyo

    170 posts

    Well it’s great then, and I’ll migrate to DMZ!

    Thanks guys!

  • #662 / Mar 16, 2009 1:09pm

    tdktank59

    322 posts

    It keeps all original functionality it just adds more features! that make it easier to use and manage.

  • #663 / Mar 16, 2009 2:10pm

    OverZealous

    1030 posts

    Mornin’ All (er… Afternoon…),

    I don’t really consider this a fork.  I’m hoping that once stensi has more free time, he and I can work on merging my code back into the DataMapper base.  I decided to rename it to help distinguish this version, since I’m not really trying to maintain DataMapper itself.

    The majority of the new features are geared around managing relationships, which was kinda weak in the current version of DataMapper.  I think I also made a few tweaks to DataMapper, fixing some minor bugs, etc.  Hopefully none of them will cause any issues.

    @OES: None of the new features appear to have any affect on the code you wrote.  If any of those relationships are one-to-N, you can modify your tables by dropping the join table and adding <model>_id to the one side of the relationship.  Of course, you’ll want to migrate your data.  Also, if the Post is the one side of the relationship, you could save a whole query by using join_related($model, $fields).

    If anyone has any questions, or suggestions, for the new features on DMZ, please shoot me a private message.

  • #664 / Mar 17, 2009 12:53pm

    MirceaBotez

    3 posts

    Hi, I have run into an issue using DM, it relates to deleting from a table.
    What happens is we delete via ajax an item (from a list) and then redisplay the list. For some reason, DM deletes the object from db BUT keeps it in memory. A restart of server gets rid of the item.

    In Java, there were different “flush” mechanisms that I could call on Hibernate to remove the item from it’s cache. Does anyone know of such an method call/mechanism with DM?

    Has anyone else encountered this issue?

  • #665 / Mar 17, 2009 1:06pm

    OverZealous

    1030 posts

    DataMapper does not “cache” by default.  Also, PHP doesn’t have any in-memory objects beyond a single HTTP request unless you’ve enabled some kind of PHP-level caching, because every call to PHP is like starting from scratch.

    One of two things are most likely happening:

    Either you’ve enabled the ActiveRecord-based caching mecahnism, in which you’ll need to read the docs on how to clear the cache, etc, or

    The way DM handles objects is tripping you up 😊  When you delete an item from DM, that deletes the row from the database immediately (or when the transaction completes).  But that doesn’t change anything in memory.  To update an ->all array, simply call ->get() again (you might need to re-configure your query, as well).  Due to some issues with PHP and memory management, there is actually no practical way to know that an item was deleted and needs to be removed from a parent’s ->all array.

    Alternatively, it might be possible to handle all of your deletes and updates before your longer queries.

  • #666 / Mar 17, 2009 7:21pm

    tdktank59

    322 posts

    @ OverZealous

    Just letting you know Ive got your new version ill let you know if there are any bugs that I can find. (I think Ive figured out all my stupid learning mistakes if you consider them stupid since I was learning after all lol)

  • #667 / Mar 19, 2009 11:29pm

    macigniter

    244 posts

    I am currently trying to port the DM class to PHP4 since after a long discussion with one of my clients there is no other way of hosting the application on a PHP4 server :( Unfortunately I have already set-up the whole application with DM and it is running beautifully with PHP5.

    I know it’s a bad idea to downgrade but there really is no other way right now so I am trying to run the application with DM for PHP4.

    I already managed to implement a workaround for the static class variables ‘config’ and ‘common’ which works flawless.

    I also transformed the autoload() function into a PHP4 compatible version. The only downside is, that DM’s __get and __set function do not work properly. Also I currently don’t see a solution to make __toString work. I got __call and __clone to work though.

    My question now is:
    - Are the magic methods __get, __set, and __toString REALLY needed for full functionality of the lib?

    Since my application is running on PHP4 now (of course without some code limitations like method chaining…) I was wondering if DataMapper is really dependent on the magic methods stated above.

    OverZealous, Stensi, I would really appreciate your professional insights! (Although I know you would rather slap me in the face for trying to make DM work with PHP4… I know and I really feel bad about it myself)

  • #668 / Mar 19, 2009 11:46pm

    OverZealous

    1030 posts

    Yes, the magic method __get is really needed for the library, otherwise you have to create a bunch of useless fields for every possible relationship, instantiating every single possible related class (that includes looking up all of those model’s fields, for example.)  (Update: actually, this flat-out wouldn’t work.  Every model would keep looking up every other model, recursively.)

    And DM uses the __get method of looking up classes internally.

    One alternative would be to make a “smart” class that you assigned for every related object, that handled setting up the relationship, but that would be almost as much work as writing DM all over again!  It might look something like this:

    // in DM's constructor
    $arr = $this->has_one + $this->has_many;
    foreach($arr as $field) {
        // do NOT relate $this to DMLoader, or your memory usage will spike because
        //    PHP will never free anything due to circular references.
        $this->{$field} = new DMLoader($this->model, $this->id, $field);
    }
    
    class DMLoader {
        DMLoader($parent_model, $parent_id, $field) {
            $this->parent_model = $parent_model;
            $this->parent_id = $parent_id;
            $this->field = $field;
        }
        // somehow replicate everything that DM does, actually calling the real model as needed.
    }

    In short, yes, it is really, really necessary to make DM work.  PHP4 is probably just not going to cut it.

    __toString and __clone are only necessary if you use them.  If you don’t, I don’t think they are used internally.

  • #669 / Mar 20, 2009 5:43am

    cahva

    662 posts

    I am currently trying to port the DM class to PHP4 since after a long discussion with one of my clients there is no other way of hosting the application on a PHP4 server :( Unfortunately I have already set-up the whole application with DM and it is running beautifully with PHP5.

    I know it’s a bad idea to downgrade but there really is no other way right now so I am trying to run the application with DM for PHP4.

    Sorry have to comment this one. Have you absolutely told the client the benefits of PHP5 and told them that PHP4 is at the end of its road as its discontinued over a year ago? Old sites will usually work with PHP5 also and you can set a few configuration values to PHP if theres old-skool usage of register globals, long arrays(eg. $HTTP_SERVER_VARS, $HTTP_POST_VARS etc.).

    I work in a hosting company and these are the configuration values in vhost that usually are needed to get old PHP4 code working:

    php_flag register_globals 1
    php_flag register_long_arrays 1

    Theres really not much more to it. During years there have been only couple of times that we had to alter the code itself and if I remember right, it was due differences with objects where objects were destroyed with $this = null; which wont work with php5.

  • #670 / Mar 20, 2009 7:05am

    quasiperfect

    132 posts

    i’m using the original datamapper

    what i want to do is this

    save a new object let’s say user (it doesn’t exist in the db that’s what i mean by new)
        save a existing group to this user
        save 2 new (it doesn’t exist in the db that’s what i mean by new) books to this user
    all of this in one shot so if one save fails i need all the thing to fail

    my code is

    $u = New User();
    $u->name = 'test';
    $g = New Group();
    $g->where('id','1')->get();
    $b = new Book();
    $b->name = 'b1';
    $bb = new Book();
    $bb->name = 'b2';
    $u->save(array($g,$b,$bb));

    the problem is that it saves the user it saves the group relation but not the books

    i looked at the debug data and it doesn’t even try to insert the books or the relations between the books and user
    any idea ?

  • #671 / Mar 20, 2009 1:12pm

    OverZealous

    1030 posts

    @quasiperfect
    This has been covered many times on this board.  You still must save the new objects first.  $obj->save() will only save $obj to the database, and any related items.

  • #672 / Mar 20, 2009 1:34pm

    bEz

    110 posts

    i’m using the original datamapper

    what i want to do is this

    save a new object let’s say user (it doesn’t exist in the db that’s what i mean by new)
        save a existing group to this user
        save 2 new (it doesn’t exist in the db that’s what i mean by new) books to this user
    all of this in one shot so if one save fails i need all the thing to fail

    my code is

    $u = New User();
    $u->name = 'test';
    $g = New Group();
    $g->where('id','1')->get();
    $b = new Book();
    $b->name = 'b1';
    $bb = new Book();
    $bb->name = 'b2';
    $u->save(array($g,$b,$bb));

    the problem is that it saves the user it saves the group relation but not the books

    i looked at the debug data and it doesn’t even try to insert the books or the relations between the books and user
    any idea ?

    @quasiperfect
    Based on the reply from OverZealous,
    What is the (or is there a)  relationship between user and book?
    Also, which version are you using:  DM or DMZ?

  • #673 / Mar 20, 2009 1:38pm

    OverZealous

    1030 posts

    @bEz
    He says he’s using the original RIGHT at the top of your quoted section.
    Also, it doesn’t matter which version.  You always have to save objects before saving relationships.

    I also think I should clear something up.  This:

    $g->save();
    $b->save();
    $bb->save();
    $u->save();
    $u->save($g);
    $u->save($b);
    $u->save($bb);

    and this:

    $g->save();
    $b->save();
    $bb->save();
    $u->save(array($g, $b, $bb));

    Do the exact same thing!  DataMapper doesn’t do anything magical to make the save take less writes to the database.  It is just cleaner to read.

  • #674 / Mar 20, 2009 2:41pm

    macigniter

    244 posts

    Sorry have to comment this one. Have you absolutely told the client the benefits of PHP5 and told them that PHP4 is at the end of its road as its discontinued over a year ago? Old sites will usually work with PHP5 also and you can set a few configuration values to PHP if theres old-skool usage of register globals, long arrays(eg. $HTTP_SERVER_VARS, $HTTP_POST_VARS etc.).

    I have tried to convince them with lots of arguments, but they are running several old scripts on the server and since money is an issue for everyone these days there is no way of running the new application on a seperate server without porting their old data. I’d really rather run it on PHP5 :(

    I was also thinking of using an .htaccess file to switch their old applications to PHP4. Do you think that would be a viable solution?

  • #675 / Mar 20, 2009 3:04pm

    OverZealous

    1030 posts

    I forgot to mention that when I googled php4 __get, the first link turned up some ways to get __get-like functionality working in PHP4.  It was a long article, so I didn’t actually read through the whole thing.

    Also, check out http://hurring.com/scott/howto/php4_and_php5/ for tips on getting PHP4 and 5 running together on one server.  (An .htaccess file should work just as well).

    It looks like it isn’t too difficult to get php4 running in one directory, and php5 running in another.  I think that’s definitely your best option!

    Alternatively, since CodeIgniter has only one startup file (index.php), you might be able to rename that one file .php5 (if the server is configured for it), and just update your config.

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

ExpressionEngine News!

#eecms, #events, #releases