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-22-2009

[eluser]OverZealous[/eluser]
Multiple DataBases really wouldn't work with DM, because it's main goal is to help with mapping relationships to objects. There isn't much call for mapping relationships across multiple DBs.

Second, if I understand correctly, are you trying to merge multiple rows into one row?? That is an incredibly bad idea, as it makes the database really inefficient. There is no reason why your DB can't handle hundreds-of-thousands of rows, unless it really sucks (like Access or something). Just set up proper indexing. If you know the database is read heavy, you can go nuts on the indexes to really help queries run faster.

Finally, DataMapper (original) doesn't handle multiple relationships to the same object very well. My extension (DMZ, search this board) handles them better, but what you are doing doesn't look much like a highly normalized DB. Unless your DB is normalized, I doubt DM will work for you, much less be very efficient.


DataMapper 1.6.0 - El Forum - 04-22-2009

[eluser]warrennz[/eluser]
Hey OverZealous

Thanks for yet another very good reply

The db/tables in question are managed by a proprietary system that I have no control over and the tables them selves are essentially logs (of the beaten track its a radius server and the logs are internet usage and connectivity logs). Querying them isn't really a problem in terms of performance I just didn't think it was a very good idea to duplicate a relationship row for every record given than there are a allot of them.

Anyway, ill just stick to standard CI's AR for the moment.

I tried for along time to get multiple relationships on the smae object to work with DMZ but just couldn't. Maybe ill have another crack at it when I understand what DM(Z) is doing a bit more Tongue

Thanks again OverZealous

On a slightly different note, is there anyway to store a 'created_on' field in the relation table? and have DM set the right time etc like it does with a normal model. Could just use a trigger I surpose..


DataMapper 1.6.0 - El Forum - 04-22-2009

[eluser]OverZealous[/eluser]
There's nothing in DM currently to handle dates on relationship tables. I never thought of that.

I apologize that DMZ is complicated. The real problem was trying to shoehorn better relationships into the DM design. Personally, I'd prefer to have the all of the relationship data stored in a single file, so that a lot of the duplicate information could be parsed automatically. However, DM just isn't set up for that, and I didn't want to break any existing code to make it work.

I've thought about writing a little JS/PHP application to help kickstart a DMZ project by allowing you to describe the models and relationships, and then having it kick out the PHP code. But I've been extremely busy, and just haven't had the time.


DataMapper 1.6.0 - El Forum - 04-23-2009

[eluser]Peet86[/eluser]
Hello Guys!

I want to translate this query to Datamapper methods, but I have some preblemes with:

Code:
SELECT node.name, (COUNT(parent.name) - 1) AS depth
FROM nested_category AS node,
nested_category AS parent
WHERE ...

I found the count function in Datamapper documentation, but how can I define the "AS" ?
I dont want to make new models for self referencing, because this is a nested set model query. I want to get a category tree data with this.

Thanks!


DataMapper 1.6.0 - El Forum - 04-23-2009

[eluser]warrennz[/eluser]
@OverZealous:
I see I see. Makes sense really. Will be very interested to see what happens with your DMZ project..


Re: dates - What I've done is created a 'join_created' field in the relationship table. Then created a mysql trigger to insert a time stamp when a record is created(INSERT). Then just add ...->where('join_created <','some_time_stamp')->..in my chain. Because join_created is the only field with that name it wont create an ambiguous error. This is probably really REALLY bad design but I don't have any other quick fix for now Tongue. I don't understand DM(Z) enough to extend it to support created and edited fields in the relationship table, maybe someone else does? Smile


DataMapper 1.6.0 - El Forum - 04-23-2009

[eluser]OES[/eluser]
I have a relationship table which links users to categorys. Is it possible for DM query to check to see if a user is part of that category.

In normal AR its a simple look up of the table to see if the user_id & category_id excists in the table. ie (model query).

Code:
function check_member($cat, $user)
    {
        $array = array('category_id' => $cat, 'user_id' => $user);
        $this->db->where($array);
        $query = $this->db->get('categories_users');
        if ($query->num_rows() > 0){
           return TRUE;
        }
        return FALSE;

    }

Any suggestions on if this can be done via DM instead.

Hope you can advise.


DataMapper 1.6.0 - El Forum - 04-23-2009

[eluser]warrennz[/eluser]
Code:
$u = new User()
$u->get_by_id($UserID);

return $u->category->get_by_id($CatID)->exists()? true : false;

EDIT:
Explanation

$u is your user object
$u->category->get(); will return all the rows of categories that belong to that user( depending on relationship type - many or one etc)

$obj:get_by_id() is essentially an extension of where('id','someid');

So $u->category->get_by_id($catID); will firstly limit the query down to all categories that belong to that user, then (as per get_by_id) limit it down to the category with that $CatID

This what you mean?


DataMapper 1.6.0 - El Forum - 04-23-2009

[eluser]OES[/eluser]
Go Damn. I didnt see the excists function.

Much better.

Perfect than you


DataMapper 1.6.0 - El Forum - 04-23-2009

[eluser]warrennz[/eluser]
You're welcome

To note

exist() runs

if(empty($this->id))
...

$this->id being, in your case, the category id - not the relationship category id but the actual category table id. SO, if the category relationship is there but the resulting category is not, exists() will return false.


DataMapper 1.6.0 - El Forum - 04-23-2009

[eluser]naren_nag[/eluser]
I have a table called people, a table called workexperiences and a table called companies. I have three corresponding models: person, workexperience and company.

A person has many workexperience
A workexperience has one company

After adding two hundred relationships between person and workexperience, the database has stopped saving relationships in the join tables.

So individual records continue to get added to people, workexperience and company. But none of the join tables are getting populated.

The last auto id in the people_workexperiences join table is 199.
The last auto id in the companies_workexperiences join tables is 150.

Has anybody come across a bug of this sort?