CodeIgniter Forums
[Deprecated] DMZ 1.5.3 (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: [Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) (/showthread.php?tid=18196)



[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 07-17-2009

[eluser]OverZealous[/eluser]
jpl
That's a good suggestion, and I'll look into it in the future. I'm working on a fairly important update to DMZ, so I might not get it looked at right away.

I'm curious as to why you don't use the built-in validation routine, though. Is there something wrong with the way DataMapper validates for you?


[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 07-17-2009

[eluser]OverZealous[/eluser]
jpi
I was able to easily add your recommendation to the next release. form_validation is now loaded dynamically upon first use. (Due to the way it DMZ expects form_validation to work, it is actually loaded the first time $object->form_validation is called, where $object is any DataMapper object.)


[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 07-17-2009

[eluser]jpi[/eluser]
Quote:I’m working on a fairly important update to DMZ
Good news. I am waiting forward to see it. Maybe this next release will reduce the number of database queries that DMZ make. For instance CI Profiler tells me 5 queries were made when i only expect 3 of them. I am talking about this kind of queries :
Code:
SELECT * FROM `users` LIMIT 1
(when I instantiate new model <-- I know what is the goal of this query, but I rarely access to the first row right after I instantiate a model).

Quote:I’m curious as to why you don’t use the built-in validation routine, though. Is there something wrong with the way DataMapper validates for you ?
Not at all. It's just that I am not used to give models the data validation task. Since I discovered CI, I have always seen the validation in the controller. And by the way, i have been playing with DMZ for only 2 days Smile

Quote:I was able to easily add your recommendation to the next release
Great ! I don't know if many people will benefit from this tiny change, but it's usefull to me so thank you again Smile


[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 07-17-2009

[eluser]OverZealous[/eluser]
Those queries you reference are actually caused by CI's get_fields() method. It is used to determine the names of the fields available on the table. You can reduce them, through the production cache (I can't link to it at this moment, but it's in DMZ's docs).

However, be careful. Turning on the cache while in development will cause errors and possibly data corruption. You should only enable it on production servers that have no active development, and clear the cache whenever any changes are made.

Also, I would bet that the fields query is insignificant in terms of resource cost.

Overall, DMZ has an extremely low query overhead for an ORM.

Finally, you should still be doing all validation in your controller, even with DMZ. I recommend using a structure like this:
Code:
function edit($id) {
    $u = new User();
    $u->get_by_id($id);
    if($this->input->post('submit')) {
        $u->name = $this->input->post('name');
        if($u->save()) {
            redirect('users/view/' . $u->id);
        }
    }
    $this->load->view('user_edit', array('user' => $u));
}

Then in your view, you can check to see if $user->error->all is empty to decide if an error occurred, as well as get your form input re-filled out for free.

(Sorry if there are errors, I'm typing this on a netbook. Tiny keyboards suck!)


[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 07-20-2009

[eluser]cberk[/eluser]
Is there a way with DMZ to include calculated fields in the object when writing a custom sql query? Basically, I would just like it to trust me and pick up all the fields in the table result and allow me to access them through the object.

I've noticed that custom fields are included if my query returns one row, and I reference the original object, but what I need is the ability to access these fields when I loop through the $object->all array.

Here's a code example:
Code:
$m = new Metro();
$m_sql = "SELECT `normal_metros`.*, COUNT(`join_listings_metros`.`metro_id`) as `num_listings`
        FROM `normal_metros`
        etc, etc, etc................
        GROUP BY `normal_metros`.`id`";
$m->query($m_sql);

foreach ($m->all as $metro)
{
    echo $metro->num_listings; // This value isn't stored in the object, even though it was created in the query.
}



[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 07-20-2009

[eluser]bEz[/eluser]
[FAST REPLY]
Before Phil adds assistance let me add this.

If DMZ supports querying VIEWS (which it should), why not create your calculations that way?


[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 07-20-2009

[eluser]cberk[/eluser]
bEz:

The problem isn't generating the data table with a query/view, the problem is getting DMZ to use all the fields in the result, instead of just the fields in the normal_metros table.


[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 07-20-2009

[eluser]OverZealous[/eluser]
@cberk
DMZ always includes every column you select. This is different from DataMapper, where it only included columns that were on the database.
Just make sure you give it an alias!

Example:
Code:
$m->select('*')->select('COUNT(`join_listings_metros`.`metro_id`) as `num_listings`')->get();
echo $m->num_listings

--

@Everyone: DMZ 1.4 is nearing release. This ended up being a serious update, including performance improvements, lots of requested features, and some really exciting new extensions. I don't want to ruin the surprise, but if I can recover from coding all night long, I'm going to try to get a copy released soon (tonight or early tomorrow).


[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 07-20-2009

[eluser]OverZealous[/eluser]
@bEz
DMZ does not support querying views. If you would like to provide me with some information as to how you would use views within DMZ, I'll think about adding it in the future.

I'm not sure that enough people are wanting to use views. However, it might be something that can be implemented using an extension.


[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 07-20-2009

[eluser]bEz[/eluser]
@phil
Good to know, as you saw I was unsure of it's availability.
I will provide you with a more descriptive example I have in mind sometime after 1.4 is released and things have calmed down.

The reason is:
1) You are going to be highly sought to assist with the new features.
2) I would like to get assistance on use of the "production cache" feature.


In brief, the application I am rebuilding for CI/DMZ can be very taxing on the mysql server. Aside from the noted development advantages gained by using DMZ, I still find myself needing to "include_related" through 3-5 tiers of related tables. It is here where I am looking for a VIEW to work in my favor.