Part of the EllisLab Network
   
44 of 80
44
[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition)
Posted: 07 August 2009 11:09 PM   [ Ignore ]   [ # 431 ]  
Grad Student
Avatar
Rank
Total Posts:  88
Joined  03-19-2009
OverZealous - 07 August 2009 10:32 PM

Before:

$users = new User();
$users->where_related('group''name''Administrator')->get();
// Loop over all administrators
foreach($users->all as $u{
    
// do stuff

After:

$users = new User();
$users->where_related('group''name''Administrator')->get();
// Loop over all administrators
foreach($users as $u// <--- This line here!
    // do stuff

As you can see, it’s a little easier to read, and one less “gotchya” type of mistake.  It’s especially nice with the 1.4.0 ability to seamlessly use (standard) plural relationship names:

// assume we know the group ID we want:
$group = new Group($group_id);
$group->users->get();
foreach(
$group->users as $u{
    
// do stuff

One caveat:
This completely breaks the (rarely-used) ability to do this:

foreach($user as $k => $f{
    
echo("user->$k = $f\n");

If I find that this is breaking a lot of existing code, I might pull it.  If it only breaks a little, I have a workaround.  If it doesn’t break any, I’m leaving it as is.

Thank you man !!

Great stuff !!! One less detail to get us stucked !

:D

Profile
 
 
Posted: 09 August 2009 09:39 AM   [ Ignore ]   [ # 432 ]  
Summer Student
Avatar
Total Posts:  2
Joined  08-09-2009

Hi there,

I have a problem with my login script (which is based on the dmz example included in the download) as well as with the example itself, if I use it directly.

The problem:
It’s always possible to login with a blank password field (in my code as well as in the example). A wrong password (with at least one character) doesn’t work, the correct one works fine to login.

Maybe there should be an additional check if the password value is empty, or the validation doesn’t work as it should or maybe I’m overlooking something else.

Would appreciate some hints. smile I’m going crazy right now.

Thanks.

Profile
 
 
Posted: 09 August 2009 10:31 AM   [ Ignore ]   [ # 433 ]  
Summer Student
Total Posts:  13
Joined  12-13-2007

i have problem to load a related table. example
table grade
- id
- grade_name

table school
-id
-grade_id


i create 2 model

class grade_model extends DataMapper 
{
    
var $model 'grade_model';
    var 
$table 'grade';
    
    function 
__construct($id NULL)
    
{
        parent
::__construct($id);
    
}
}

class school_model extends DataMapper 
{
    
var $model 'school_model';
    var 
$table 'school';
    var 
$has_one = array('grade_model');

    function 
__construct($id NULL)
    
{
        parent
::__construct($id);
    
}

is my code correct? can we add some class suffix like that? how can i display my data using join?

Profile
 
 
Posted: 09 August 2009 01:36 PM   [ Ignore ]   [ # 434 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1026
Joined  10-08-2008
superflausch - 09 August 2009 09:39 AM

It’s always possible to login with a blank password field

You know, this has come up before.  I finally did some research, instead of my usual recommendation (manually check for empty passwords).  The solution, it turns out, was to change a long-standing piece of code (since stensi managed this) in _to_array().

Anyway, I fixed it, and since it is fairly important, I quickly updated DMZ.

DataMapper OverZealous Edition 1.4.3 Update

Version 1.4.3: This update includes a bugfix when using validate->get.

Download the Latest Version Here

  View the change log and the upgrade process
  Having issues? Please look through the Troubleshooting Guide & FAQs
  View the Complete Manual

 Signature 

Phil DeJarnett
  OverZealous Creations, LLC
  ZESTYJOBS - Job Management Powered by CI/DMZ

  DataMapper OverZealous Edition: Advanced ORM for CodeIgniter Discuss

Profile
 
 
Posted: 09 August 2009 01:45 PM   [ Ignore ]   [ # 435 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1026
Joined  10-08-2008
Bnoe - 09 August 2009 10:31 AM

is my code correct? can we add some class suffix like that? how can i display my data using join?

Your code is not correct, because you have not specified the relationship from grade_model->school_model.

DMZ expects fairly strict table names.  You really should follow the recommendations in the guide, using plural names for your tables, singular names for your models.  If you have errors when not using these rules, they are most likely the cause.

If you are having trouble understanding how to use DMZ, the manual provides a lot of well-formatted, fairly clear examples.  You really need to read through the entire General Topics group of pages.

 Signature 

Phil DeJarnett
  OverZealous Creations, LLC
  ZESTYJOBS - Job Management Powered by CI/DMZ

  DataMapper OverZealous Edition: Advanced ORM for CodeIgniter Discuss

Profile
 
 
Posted: 09 August 2009 03:15 PM   [ Ignore ]   [ # 436 ]  
Summer Student
Avatar
Total Posts:  2
Joined  08-09-2009
OverZealous - 09 August 2009 01:36 PM

You know, this has come up before.  I finally did some research, instead of my usual recommendation (manually check for empty passwords).  The solution, it turns out, was to change a long-standing piece of code (since stensi managed this) in _to_array().

Anyway, I fixed it, and since it is fairly important, I quickly updated DMZ.

I may overlooked those posts. Thank you for the new release and the quick answer.

Cheers.

Profile
 
 
Posted: 09 August 2009 06:34 PM   [ Ignore ]   [ # 437 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1026
Joined  10-08-2008

I want to notify everyone of a small problem with the new validate-get method:

Before, the method would only query on non-empty() fields.  This meant that an empty password would be simply be ignored, which was the original issue.  (This didn’t affect username, because you need at least username to look up the user.)

So I changed that to only query non-NULL fields.  This eliminated the empty field issue.  It did, however, create an entirely new issue:  If you (like me) use the trim pre-processing rule before the required rule, a NULL field will be converted into ’‘ (empty string), due to the way the trim method works.

Therefore, the logins on my application failed.

My proposed solution is to add a _trim rule directly to DMZ, that ignores empty fields.  This seems to work very well.  I don’t want to implement it until I have had more time to test, though.

If you are having trouble with 1.4.3, Add this to either libraries/datamapper.php or any class that uses required, trim, and gets looked up with validate->get:

/**
 * Trim
 * Custom trim rule that ignores NULL values
 *
 * @access    public
 * @param    string
 * @return    bool
 */    
function _trim($field{
    
if( ! empty($this->{$field})) {
        $this
->{$field} trim($this->{$field});
    
}
 Signature 

Phil DeJarnett
  OverZealous Creations, LLC
  ZESTYJOBS - Job Management Powered by CI/DMZ

  DataMapper OverZealous Edition: Advanced ORM for CodeIgniter Discuss

Profile
 
 
Posted: 09 August 2009 08:44 PM   [ Ignore ]   [ # 438 ]  
Summer Student
Total Posts:  13
Joined  12-13-2007

hmm.. it will be difficult touse dmz on non english language or we adopt non english database. any suggestion?

Profile
 
 
Posted: 09 August 2009 09:05 PM   [ Ignore ]   [ # 439 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1026
Joined  10-08-2008
Bnoe - 09 August 2009 08:44 PM

hmm.. it will be difficult touse dmz on non english language or we adopt non english database. any suggestion?

Many people use it with non-English systems.  There is no language database, DMZ just uses the inflector helper to convert the model or table name if they are not provided.

If you don’t use it with English, you can still specify the table name in your language.  My comment was that you should stick with the recommended model/table naming scheme.  Unless you have a very good reason to avoid it (usually legacy databases), it makes it easier for me (and other DMZ users) to support.

There is only one location in the current DMZ where the inflector code is used without an alternate option: and that is when naming many-to-many self-relationship join tables (scroll down to Self Relationships).  In this case, to ensure unique relationships, the table name is generated using plural($this->model) and plural($other->model), according to the rules linked above.

So, unless you plan to use many-to-many self-relationships, you can always safely override $model and $table to be whatever you like.  You are also free to write / provide your own version of inflector helper.  Just replace the inflector_helper.php that comes with DMZ.

(You also lose the ability to reference relationships using the plural form, such as $user->groups.  But that doesn’t break anything, just code readability.)

 Signature 

Phil DeJarnett
  OverZealous Creations, LLC
  ZESTYJOBS - Job Management Powered by CI/DMZ

  DataMapper OverZealous Edition: Advanced ORM for CodeIgniter Discuss

Profile
 
 
Posted: 10 August 2009 03:03 AM   [ Ignore ]   [ # 440 ]  
Grad Student
Rank
Total Posts:  37
Joined  07-10-2009
OverZealous - 07 August 2009 09:26 PM

@mcnux
I looked at the docs, it doesn’t say that.  You cannot pass in an array.  You can use an array on the default_order_by, you can pass in a comma-delimited string of items, or your can add them one-by-one, but you can’t use an array on the order_by method.

If I’m missing something, let me know.

My bad! Sorry.

Profile
 
 
   
44 of 80
44
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 819, on March 11, 2010 11:15 AM
Total Registered Members: 149963 Total Logged-in Users: 44
Total Topics: 103610 Total Anonymous Users: 5
Total Replies: 518110 Total Guests: 408
Total Posts: 621720    
Members ( View Memberlist )