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 - 04-21-2009

[eluser]warrennz[/eluser]
Heya

I have a strange problem

With my current db design I have a 'comments' tables. This table stores the user_id (the user this comment is FOR) and the posted_id (this user who posted that comment). Both users originate from the same 'users' table and are done via the users model.

Moving that to a linking table for datamapper I now have comments_users which I use to get a users comments ($u->comments->get()->all)

How, if possible, can I define that 2nd relationship.. to the same table.. I have no idea how it can be done if at all.

I would prefer to avoid making a 2nd 'users2' model if possible.

Currently theres the users : comments relationship which is 1:M. Then the posted user would be a 1:1 relationship with the same user table, e.g. comments->posteduser->get()

Any ideas would be very appreciated Smile Thanks so much. Im totally lost on this one haha


DataMapper 1.6.0 - El Forum - 04-21-2009

[eluser]OverZealous[/eluser]
Please look into my extended version of DataMapper, because the current version does not support multiple relationships with the same object. I'm in the middle of something, but it is linked on this board, just a few pages back. Look for "DMZ".

It also supports keeping 1-N relationships in the table as "user_id" and "posted_id", which is convenient.


DataMapper 1.6.0 - El Forum - 04-21-2009

[eluser]warrennz[/eluser]
I take it 1:N relationships with an individual id linking table will no longer work with DMZ?


DataMapper 1.6.0 - El Forum - 04-21-2009

[eluser]OverZealous[/eluser]
Nope. Everything still works as is. It's a drop-in replacement.


DataMapper 1.6.0 - El Forum - 04-21-2009

[eluser]warrennz[/eluser]
Hmm well I have no idea what was going on there but I renamed my model to comments from notes and everything works as expected now. Still using the same db tables naming etc.

Oh well Smile beats me

Thanks


DataMapper 1.6.0 - El Forum - 04-22-2009

[eluser]ale21ale[/eluser]
HEllo my friends !

I have a doubt. How can I manage datamapper from a LOCK TABLE in Mysql?.
Using transactions in my application but there are records that can be accessed by users and 2 if a user is editing the record and another user deletes an error occurs in the DB. How do you solve this?


DataMapper 1.6.0 - El Forum - 04-22-2009

[eluser]OverZealous[/eluser]
You have to manage that in the application. Like you would in any application. DataMapper is just glue. You still need to build the structure yourself.

If you need object or row locking, you'll have to manage it yourself.


DataMapper 1.6.0 - El Forum - 04-22-2009

[eluser]ale21ale[/eluser]
Sorry Phil. Is that the question could have been very stupid. I use google translator jeje I not write in English very well. I know the lock tables are managed by the database engine, thought he could have some method in the library datamapper.


DataMapper 1.6.0 - El Forum - 04-22-2009

[eluser]OverZealous[/eluser]
Ahh, I apologize, then!

Hopefully it came across, then, DataMapper does not handle anything like locking. You'll need to manage in your own code.

If you come up with a standardized way of locking a row, you can always add it to a subclass of DataMapper, and then use that as your base class for your models:
Code:
class DataMapperLocker extends DataMapper {
    
    function is_locked() {
        // look up and return whether this row is locked, based on $this->id.
    }
    function lock() {
        // handle locking the row or object
    }
    function unlock() {
        // handle unlocking this row or object
    }
}

// in your class
class MyWidget extends DataMapperLocker {
    // configure like normal
}

This is something I've been wanting to do as well, however, it requires a lot of interface coding, so I've been putting it off. The biggest issue for me is the more complex issue of asynchronous editing, and ensuring that rows are unlocked when necessary. Otherwise it can be really annoying for end users if someone locks a row, but then gets disconnected.


DataMapper 1.6.0 - El Forum - 04-22-2009

[eluser]warrennz[/eluser]
Is there anyway that datamapper supports multiple databases? Can this sort thing even support multiple data sources?

I've had a good look throughout the files and nothing seems to give any indication it does.

Maybe I could just redefine $this->db at the start of my model with a new db config, and then on __destruct() reset it to the 'default' db config. Ideas?

And also, anyway to do this sort of thing or is datamapper not really intended for that..
example.png


Thanks!