Welcome Guest, Not a member yet? Register   Sign In
[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition)

[eluser]OverZealous[/eluser]
You always have to select the 'id' column, due to an old quirk from the original DataMapper. I'd fix it, but I know that it would break a lot of existing code.

So, add select('id'), and you should be all set.

[eluser]mrtavo[/eluser]
[quote author="mrtavo" date="1248265921"][quote author="OverZealous.com" date="1248264869"]Yes, you can, very simply!

The DataMapper database needs to be the default in CodeIgniter. Then, whenever you need the second DB, use the instructions provided in the CodeIgniter manual. (Scroll down to Connecting to Multiple Databases.)

You can then use DataMapper like normal, and SELECT on your other DB using traditional CodeIgniter methods (include ActiveRecord).[/quote]


Thanks very much for the quick reply Big Grin I will try that soon.[/quote]


Hello again, I tried to do that, but to get it work properly I had to load my "default" database too in the same function (I don't know if I'm doing something wrong, or if this is the right way to do it).

I'll illustrate this with an example:

function F(){
$A = new A();
A->where_related_X('id', 1)->get();
/* do something with A */
$ExtDB = $this->load->database('extdb', TRUE);
/* that seems to change the default active database */
$r = $ExtDB->query('somequery');
/* do something with r->result() */
(*)
$B = new B();
$B->where_related_A('id', 2000)->get();
/* this gives an error because is using the external database */
}

I needed to add in (*) row the following code to make this work:
$mydb = $this->load->database('mydefaultdatabase', TRUE);
which seems to change the default active database.

Am I doing something wrong ?
Is this the right way to do it ?

the $active_group variable is set properly at the very beginning.

[eluser]Daniel H[/eluser]
Only just noticed that you have released 1.4.0 - brilliant; really amazing work Phil. I hope you realise how much we all genuinely appreciate your hard work.

[eluser]OverZealous[/eluser]
@mrtavo
Well, I've never used CI with multiple databases, so I can't help beyond that. I assumed (we all know what that means) that CI wouldn't change the default database when loading auxiliary ones.

What you suggested doing (loading the second database, then reload the first) is how I would have handled it. And then go file a bug report with CodeIgniter, saying that load->database shouldn't replace the default if the second parameter is TRUE. ;-)


@Daniel H
Thanks! I really appreciate it!

[eluser]rayray[/eluser]
I'm looking to possibly migrate from IgnitedRecord over to DataMapper. My schema has one funky thing that I can't quite get to work properly in DMZ. I have 2 tables: users and events. Users has_many events and events has_many users. No problem here. But users can be associated with an event as a user, administrator, or both. In IgnitedRecord, to solve this by creating 2 join tables, one named 'events_users' and the other 'administrators_events'. IgnitedRecord allows you to specify a name for the relationship and the name of the join table for that relationship. The relationship looked like this:

Code:
Class User extends IgnitedRecord{
  public $has_and_belongs_to_many = array(
    array('table'=>'events', 'name'=>'admin_events', 'join_table'=>'administrators_events'),
    array('table'=>'events', 'name'=>'events', 'join_table'=>'events_users'));
}

Class Event extends IgnitedRecord{
  public $has_and_belongs_to_many = array(
    array('table'=>'users', 'name'=>'administrators', 'join_table'=>'administrators_events'),
    array('table'=>'users', 'name'=>'users', 'join_table'=>'events_users'));
}

To access the relationship in IR you'd do something like:
Code:
$users = $some_event->related('users')->find_all();
$admins = $some_event->related('administrators')->find_all();

etc...


In DataMapper is it possible to achieve the same results without changing the DB schema?

[eluser]jpi[/eluser]
Hi,
I often use 1:1 relationship. It would be a nice feature, if when I delete a row in one model, the corresponding row in the related model is also deleted automaticaly (not only in the join table). What do you think ?

Maybe it's already the case in v1.40 but in 1.32 I don't think it is.

Anyway, keep the good work. Each day I find DMZ more powerful Smile

Edit : Finally this idea is not good at all.

[eluser]PoetaWD[/eluser]
Is there a way to get a single random object ?

This will get all Persons from DB:

$obj = new Person();
$obj->get();
$data['person'] = $obj->all;

How can I get a Random person ? And have the limit set to one result ...


Thanks man

[eluser]cahva[/eluser]
@OverZealous.com
Having used the early editions of Datamapper(which was also very good), Im now testing the OverZealous edition and DAMN!!..I'm loving it! Smile You have done very good work. The extensions are great and very usefull. Its good that you have removed the original "limitation" of the database relationships (having to use relationship table for relations). Now I can really start to convert our older apps to use CI & Datamapper.

Sorry for serious ass-licking but had just to say how good work you have done with this library! Big Grin

[eluser]Jack Scott[/eluser]
Is there a simple way to detect whether a database field has changed in DMZ?

My current project involves reading data from two sources into a database table. I need to detect whether certain fields are changed by one of the sources, so the changes aren't reverted by the other one. I'm planning to add several booleans to the table, one for each important field, extending the save() method to check for changed fields, and setting the booleans before calling DMZ's save() method.

[eluser]OverZealous[/eluser]
[quote author="rayray" date="1248809433"]In DataMapper is it possible to achieve the same results without changing the DB schema?[/quote]

That is a usual layout. Please see the advanced relationships section of the DMZ manual. DMZ has specific requirements for the table and column names, so you will almost certainly have to rename and/or migrate your data.

You can, however, store $has_one relationships on the save table as the 'parent' object, using in-table foreign keys.




Theme © iAndrew 2016 - Forum software by © MyBB