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 - 03-16-2009

[eluser]gyo[/eluser]
Well it's great then, and I'll migrate to DMZ!

Thanks guys!


DataMapper 1.6.0 - El Forum - 03-16-2009

[eluser]tdktank59[/eluser]
It keeps all original functionality it just adds more features! that make it easier to use and manage.


DataMapper 1.6.0 - El Forum - 03-16-2009

[eluser]OverZealous[/eluser]
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.


DataMapper 1.6.0 - El Forum - 03-17-2009

[eluser]MirceaBotez[/eluser]
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?


DataMapper 1.6.0 - El Forum - 03-17-2009

[eluser]OverZealous[/eluser]
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 Smile 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.


DataMapper 1.6.0 - El Forum - 03-17-2009

[eluser]tdktank59[/eluser]
@ 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)


DataMapper 1.6.0 - El Forum - 03-19-2009

[eluser]macigniter[/eluser]
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 Sad 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)


DataMapper 1.6.0 - El Forum - 03-19-2009

[eluser]OverZealous[/eluser]
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:
Code:
// 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.


DataMapper 1.6.0 - El Forum - 03-20-2009

[eluser]cahva[/eluser]
[quote author="macigniter" date="1237534176"]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 Sad 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.
[/quote]
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:
Code:
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.


DataMapper 1.6.0 - El Forum - 03-20-2009

[eluser]quasiperfect[/eluser]
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
Code:
$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 ?