CodeIgniter Forums
DMZ 1.7.1 (DataMapper OverZealous Edition) - 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: DMZ 1.7.1 (DataMapper OverZealous Edition) (/showthread.php?tid=28550)



DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 03-26-2010

[eluser]tomdelonge[/eluser]
Quick question:

In the past, when I needed nested categories, I would just have a categories table and a column with parent_id. If the parent id was 0, then it mean it didn't have a parent.

What's a good way to achieve nested categories in DMZ? I imagine it has to do with self relationships. I've never needed a self relationship before, so can someone tell me: is it the right way to go for this particular problem?

Just point me in a direction.

Thanks.


DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 03-26-2010

[eluser]santiagofs[/eluser]
I’m having a problem with the include_related function.
It works ok on my local server but its not getting the related objects on the online server.
Only difference I can see is the php version. I’m running v.5.2.5 locally and v.5.2.13 online.
Does anyone having a similar issue?

Thanks.


DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 03-27-2010

[eluser]Unknown[/eluser]
Hello,

I just upgraded to 1.7.1 and I'm glad to see the new localization functions. I have a feature suggestion to make this library even more powerful, but I'm not sure if my situation is too specific.

For several of my models, some of the fields are enum types, and those correspond to lines in my language files. With the new localization features, I moved those lines into the auto-loaded model language files and created a proper naming convention for them.

Code:
<?php
// Language File for Transaction Model
$lang['transaction_amount']     = 'Amount';
$lang['transaction_account']     = 'Account';
$lang['transaction_date']         = 'Date';
$lang['transaction_type']         = 'Type';

$lang['transaction_type_deposit'] = 'Deposit';
$lang['transaction_type_transfer'] = 'Transfer';

/* End of file model_transaction_lang.php */
/* Location: ./application/language/english/model_transaction_lang.php */

Then, in the model file, I created a function to retrieve those lines.

Code:
public function localize_type() {
    return $this->localize_by_model('${model}_type_${field}', $this->type);
}

In my User model, I even gave the function some static functionality (although I haven't written it to work as a truly static function yet).

Code:
public function localize_status($status = null) {
    return $this->localize_by_model('${model}_status_${field}', ($status ? $status : $this->status));
}

In the case of that function, if no parameter is given, it defaults to the object instance's field value.

Could something like this be implemented as a magic function? For example, a function localize_{field}() which would return the line {model}_{field}_{value}, where {value} is the value of the specified field. This would make producing localized strings of enumerations incredibly easy.

I'm having a great time with DMZ, so thank you for the excellent work. :-)

Henry Merriam


DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 03-28-2010

[eluser]Cord[/eluser]
Hi guys,

I'm very new to DMZ but as a developer, I am really loving working with it. The classes are well thought out and superbly implemented. Good job Phil!

I'm trying to doing something a little unusual and am not sure if I am going to be able to achieve my goal within the limitations of the framework. I have a database (call it db_system) with two tables: users and databases. There is a many-to-many relationship between them, databases_users, which defines which databases a user has access to.

By default, CI is configured to automatically connect to the db_system database. When a user logs in to the main website and is authenticated against db_system, I want to fetch the list of other databases that the user can connect to, and then dynamically connect to each one and extract the information that is relevant to that user. Obviously, I could put all the information currently in the separate databases into a single database and reference each user's data by user_id -- but my client wants to keep them all separate because the parts of his business are discrete and he wants to be able to move any database onto a new database server with a minimum amount of fuss.

Let me explain by way of an example and hope that it's not too confusing. Assume that we have a db_system database, and two other databases: db_cars and db_houses. The structures look something like this:

db_system:
databases
database_id int unsigned auto_increment
host varchar(60)
schema varchar(40)
username varchar(40)
password varchar(30)
dbdriver varchar(10)
dbprefix varchar(20)
pconnect bit(1)
db_debug bit(1)
cache_on bit(1)
cachedir varchar(255)
char_set varchar(10)
dbcollat varchar(20)

users
user_id bigint unsigned auto_increment
username varchar(64)
password varchar(40)

databases_users
database_id int unsigned
user_id bigint unsigned

db_cars:
sales
sale_id bigint unsigned auto_increment
user_id bigint unsigned
item_id int unsigned
...

purchases
purchase_id bigint unsigned auto_increment
user_id bigint unsigned
item_id int unsigned
...

db_houses:
sales
sale_id bigint unsigned auto_increment
user_id bigint unsigned
item_id int unsigned
...

purchases
purchase_id bigint unsigned auto_increment
user_id bigint unsigned
item_id int unsigned
...

The example above is a little contrived but I think you should be able to see what I'm trying to do. A user can belong to one or more databases, and can have different information in each. The databases can reside on different servers and I want to consolidate each user's information by dynamically connecting to each database and displaying that on a single page.

I know I can use $db_params in each of the data-mapped classes but I assume that DMZ automatically connects to the database when the data-mapped object is created. I want to be able to do something like this:
Code:
$u = new User();
$u->where('username', 'is_some_user')->get();

$u->database->get();

foreach ($u->database->all as $d)
{
  // Connect to the selected database
  $user_d = some_dmz_db_connect(
              $d->host,
              $d->schema,
              $d->username,
              $d->password,
              $d->dbdriver,
              $d->dbprefix,
              $d->pconnect,
              $d->db_debug,
              $d->cache_on,
              $d->cachedir,
              $d->char_set,
              $d->dbcollat
            );

  // Now do some stuff with a user's connection
  $s = new $user_d->Sales()
  $s->where('user_id', $u->user_id)->get();
  ...
}

Does the above make sense? Is it possible to achieve what I'm trying to do or am I just barking up the wrong tree?

Thanks,
Cord


DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 03-28-2010

[eluser]Cord[/eluser]
I have another question relating to what I think would be a deep relationship in DMZ. In my previous question I mentioned a database, db_system. I would like to change the structure of the database slightly such that each databases_users row can below to a group. This would mean that, for example, user X can have access to database Y and Z but with different permission levels. The database structure would look like this:

db_system:
databases
database_id int unsigned auto_increment
host varchar(60)
schema varchar(40)
username varchar(40)
password varchar(30)
dbdriver varchar(10)
dbprefix varchar(20)
pconnect bit(1)
db_debug bit(1)
cache_on bit(1)
cachedir varchar(255)
char_set varchar(10)
dbcollat varchar(20)

users
user_id bigint unsigned auto_increment
username varchar(64)
password varchar(40)

groups
group_id smallint unsigned auto_increment
description varchar(64)
access_level int

databases_users
database_id int unsigned
user_id bigint unsigned
group_id smallint unsigned

How would I represent this relationship in the DMZ models? Clearly I would need a Databases and a Users model, and each would have a $has_many relationship with the other. But how do I add the relationship with groups, and then reference and use the `databases_users.group_id` relationship in a meaningful way?

Thanks again,
Cord


DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 03-28-2010

[eluser]OverZealous[/eluser]
[quote author="NachoF" date="1269538999"]
I want to save it all at once cause its all coming from the same form.[/quote]

You have to save each new object one-by-one. You also have to save relationships on the object as they exist.

However, if you wrap them all in a transaction, you can rollback the saves if something goes wrong. (Even when DMZ saves multiple relationships, it doesn't automatically wrap them in a transaction — if something failed, it would not automatically roll back the first items saved.)

Code:
$project->trans_begin();
// if new: save $region, $function, or $organization, too
$success = $stage->save(array($region, $function, $organization));
if($success) {
    $success = $project->save($stage);
}
if($success) {
    $project->trans_commit();
    $this->session->set_flashdata('success', 'Project Created');
    redirect("Welcome");
} else {
    $project->trans_rollback();
    // show error, etc.
}

* Note: you need a transactionable table type if you are using MySQL.


DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 03-28-2010

[eluser]OverZealous[/eluser]
@Everyone

For the other recent questions, I'm sorry I don't have time to fully respond to you all directly.

I'm accepting a new job in a new city in a different state as I write this. :cheese: This is actually great news in the long run! I'll explain in a bit.

In the short term, this means that I won't be able to provide much support or feedback for DMZ. I have a lot to do with preparing a house for being sold, packing, etc. I'll do my best, but the more in-depth answers I have been giving in the past are probably not going to be seen for a while. It will also probably be days—not hours—before I can respond to questions.

I hope that my current users will do their best to help provide answers during my transition. ;-)

The company I am going to work for uses CodeIgniter. They have been interested in the work I've done on DMZ, and I believe (although I have no guarantee of this) that DMZ will become an integral part of the work I do there.

What this may mean is that I effectively will get paid to ensure that DMZ is kept up-to-date. Even if this isn't my primary job, it hopefully will be good for the project. :coolsmile:

I'll now try to provide some feedback for the other questions. Smile

----------

@tomdelonge
Self-relationships should work perfectly. For some example of how this might look, check out the bug model, and see the dependent-dependency relationship. It's not actually used in the application, but that is how it might look. You can easily set it up with one side under $has_one, and the other stays under $has_many.

Also, in the manual, on the Advanced Relationships page, the post-related_post relationship is another good example.

Note that to save or delete a self-relationship, you'll need to specify the relationship key, like so:
Code:
$bug->save($other_bug, 'dependent');

----------

@santiagofs
For questions like this, please take the time to explain your actual problem. Otherwise we're just guessing. As it stands, I have not heard of this issue.

----------

@Henry Merriam
It would be fairly easy to write a custom magic __call or __get function. I wouldn't make it part of the core, but you could make it part of a custom class. See the second part of Using Extensions for ideas on how to do this. Make sure you call parent::__call/__get after your own customizations.

If you use this sporadically on different models, you could write an extension to provide the methods. However, extensions cannot handle magic methods, so you'd probably need to have a method more like localize_value($field, $value = NULL)

----------

@Cord
I'm not going to say it's impossible, but DMZ just isn't design to work this way. If you get it working, great!

Some tips:
• DMZ only connects to a database when it first needs it (ie: the first time $object->db is referenced).
• You can force a model to reload it's configuration for the remainder of the request (and for any new models) with the new reinitialize_model method.
• Remember that you'd have to go through this for every request.

It's too bad that you are being asked to develop it this way. As long as the access to this information is available through the same application, there is absolutely no benefit to breaking it up into different databases. It's a waste of developer time, since it provides no extra security to the users that isn't already available through normal authorization. :down:

Good Luck!

----------

Talk to you all soon! :-)


DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 03-29-2010

[eluser]PoetaWD[/eluser]
Hello Phil,

Those are GREAT news man! I am very very happy for your success! You really deserve it!

I am sure this company (can you tell us who they are?) is going to improve their prodution because they are hiring one of the best CI developers available in the market!

I hope that they use DMZ in their products and you get paid to improve DMZ. I know that we dont give you anything back but please keep your awesome script free for the community to use.

I know that I am new at PHP, but I do understand a little of the DMZ usage and I will try my bast to answer some of the questions sent here in the forum !

PLEASE DONT ABANDON US ! We love you man ! (I sure do and I am not a homo !)

DMZ made me really enjoy programming !

Thanks for everything you´ve done !


DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 03-29-2010

[eluser]OverZealous[/eluser]
@Poetawd

There's no obvious reason not to tell you the company name, but knowing the company name isn't really important, and it's probably best (since I haven't technically started yet) to keep that private for now.

Thank you for your kind words!

And to be clear, I have absolutely zero intention of abandoning the DMZ users, or the project at all. (I'm actually planning on continuing work on ZestyJobs, as well.) I probably will not have much access to the source code repository for my own projects for the first couple of weeks.

For now, I have less than two weeks to do some significant work to my home and prepare for moving to the other city! (It's a 7-8 hour drive between cities, so every time I switch back and forth I'm exhausted.) Once we are able to sell the house, and officially move, well, then things get interesting!


DMZ 1.7.1 (DataMapper OverZealous Edition) - El Forum - 03-30-2010

[eluser]Unknown[/eluser]
Hello,
I have this error and i have upgraded mysql_driver.php to the new version from here: http://svn.ellislab.com/CodeIgniter/trunk/system/database/drivers/mysql/ ( the link from http://www.overzealous.com/dmz/pages/troubleshooting.html#Database.UnknownColumn dont work )


Code:
A Database Error Occurred

Error Number: 1054

Unknown column 'ladder_games_players.dota_score_kd' in 'order clause'

SELECT * FROM (`ladder_games`) ORDER BY `ladder_games_players`.`dota_score_kd` desc


I have a table : ladder_games_players that have player_id, game_id and allot of more rows
I have set a has_many relationship because every player have more games and every game have max 10 players.

Here is the code :
Code:
$this->games->order_by_join_field('player','dota_score_kd', "desc")->get();
Sorry for my english and thx for your time.