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

Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20


[Deprecated] DMZ 1.5.4 (DataMapper OverZealous Edition) - El Forum - 11-03-2009

[eluser]bEz[/eluser]
[quote author="OverZealous" date="1257276962"]

The second is to include the data you want in the first query, saving several trips to the DB:
Code:
$u = new User();
$u->include_related('company/industry', 'name')->get_by_id(1);
echo $u->company_industry_name;
[/quote]
This is by far my favorite accessor method.
It allows my code to require "FAR LESS" comments/documentation.
O, and it just plain works! ;-)


[Deprecated] DMZ 1.5.4 (DataMapper OverZealous Edition) - El Forum - 11-03-2009

[eluser]The Mask[/eluser]
Hi, can anyone see why the validation doesn't fail when the passwords DONT match?

var $validation = array(
'mem_password' => array('label' => 'Password',
'type' => 'password',
'rules' => array( 'trim', 'required', 'min_length' => 5, 'max_length' => 20, 'xss_clean', 'encrypt' ),
'confirm_password' => array('label' => 'Confirm Password',
'type' => 'password',
'rules' => array( 'trim', 'required', 'min_length' => 5, 'max_length' => 20, 'xss_clean', 'encrypt', 'matches' => 'mem_password' )
);


The form_fields passed to the render_form method are:
array( 'mem_password' => array( 'style' => 'width:200px' ), 'confirm_password' => array( 'style' => 'width:200px' ) );

If I enter a blank confirmation password, it is also accepted !!


[Deprecated] DMZ 1.5.4 (DataMapper OverZealous Edition) - El Forum - 11-03-2009

[eluser]OverZealous[/eluser]
@The Mask
Well, the included example code works fine. Please compare your code with that.

One of these might be the issue:
• You set max_length to 20, but the example encrypt (hashing) function always outputs exactly 40 characters. Of course, since encrypt gets called after max_length, that might not be related.

• Possibly your encrypt method is broken, and is causing all encrypted passwords to end up the same value.

• xss_clean is somehow causing a problem. You should not be using xss_clean on passwords. It should only be used for unescaped HTML content that has been inserted by a user. It should never be used on content you will not display (like passwords) or content can escape at display time using the normal htmlspecialchars method.

• The order of your rules might matter. Try putting the encrypt and matches rules immediately after the required rule on both fields.


[Deprecated] DMZ 1.5.4 (DataMapper OverZealous Edition) - El Forum - 11-04-2009

[eluser]Oblique[/eluser]
I have print this problems table and for each of them i need name of user who submitted it and account number it is related to;
so isn't it abundant to use loop like this to get all of them and make many single requests to db?

Code:
$unsolved = new Problem();
$unsolved
    ->order_by('timestamp', 'desc')
    ->get_by_issolved('0');

foreach ($unsolved->all as $problem)
{
    $problem->account->get();
    $problem->user->get();
}



[Deprecated] DMZ 1.5.4 (DataMapper OverZealous Edition) - El Forum - 11-04-2009

[eluser]OverZealous[/eluser]
@Oblique
This was answered literally on the previous page, by using include_related.


[Deprecated] DMZ 1.5.4 (DataMapper OverZealous Edition) - El Forum - 11-04-2009

[eluser]The Mask[/eluser]
My problem with the login validation (passwords not matching) is fixed now.
For others who may hit this problem, I was using $u->from_array( $_POST ) which was not setting the confirm_password property because it isn't a database column.

I changed it to $u->from_array( $_POST, array( 'mem_password', 'confirm_password') ) and now it works as expected.


[Deprecated] DMZ 1.5.4 (DataMapper OverZealous Edition) - El Forum - 11-04-2009

[eluser]bEz[/eluser]
[quote author="The Mask" date="1257345100"]My problem with the login validation (passwords not matching) is fixed now.
For others who may hit this problem, I was using $u->from_array( $_POST ) which was not setting the confirm_password property because it isn't a database column.

I changed it to $u->from_array( $_POST, array( 'mem_password', 'confirm_password') ) and now it works as expected.[/quote]

The example "BUGS" application which is packaged with the latest DMz version has sample code for processing form data using the extension method => "from_array()"

I now include a function in the declaration of my models which returns a related fields array.
I used a function call in the case that I may need to provide alternative array sets and/or do complicated assignments.
Code:
/*
* rel_fields() :: currently no paramter (switch option) required.
*
* - partial/modified from Phil's example 'bugs' application
*/
$z = new Zone();
$z->trans_start();
// --------------------------------------------------------------
    $rel = $z->from_array( $_POST, $z->rel_fields() );
// --------------------------------------------------------------
$exists = $z->exists();
if ( $z->save($rel) )
{ // saved successfully, so commit ...
  $z>trans_complete();
  // Store a message
  if ( $exists ) {
    ... UPDATE SUCCESSFUL ...
  } else {
    ... INSERT SUCCESSFUL ...
  }
}



[Deprecated] DMZ 1.5.4 (DataMapper OverZealous Edition) - El Forum - 11-05-2009

[eluser]tunesmith[/eluser]
Hi, say you have a datastore with an existing schema and outside existing processes writing to those tables. Meaning, there would be a cost to changing the table names. And say the table names don't fit the DMZ convention.

I saw that the models can manually override the $table name in the class definition, but in the docs this was mentioned in regard to plurals. How far does this go, is it all right to name the table something wildly different, with different caps conventions, etc?

Also, can the names of linking tables be overridden?

Finally, regarding linking tables, can we instead make them their own objects, with an overridden table name. Is there something that makes this impossible? Here's an example:

Say you have a User, and an Event. And the linking table would (conceptually) be an Invitation. An Event can have multiple Users, and a User can be invited to multiple Events. So it's a many-to-many relationship. However, the Invitation itself might have some of its own fields, like date sent, how many times its been sent out, etc. I understand that through advanced relationships it is possible to query on those Invitation-specific fields. But what if you want to query Invitations that don't have to do with Users or Events? Like, the list of Invitations that were sent in a date range, irrespective of Users and Events.

Is it valid to instead just make an Invitation model with its own relationships? Then Users and Events would have has_many of Invitations, and Invitations would just have has_one of each. And then maybe Invitation could have an overridden table name. Does that work? It seems like any time a linking table would have extra fields, one might want to consider making it its own model.

Thanks for helping me get my head around this. As you can see, I'm trying to figure out how easily DMZ can be adapted to a schema we might not have 100% control over.


[Deprecated] DMZ 1.5.4 (DataMapper OverZealous Edition) - El Forum - 11-05-2009

[eluser]OverZealous[/eluser]
[quote author="tunesmith" date="1257473224"]How far does this go, is it all right to name the table something wildly different, with different caps conventions, etc?[/quote]

DMZ was not written with the idea that you could override table and model names completely. Some things may work incorrectly, so it isn't supported. Even if you rename tables, join table names and ITFK columns are automatically generated, and cannot be overridden. It really is best used for new or simple systems that can be redesigned to fit the expected schema.

Also, there must be a unique column called ID on every table, and it must be automatically filled.

That being said, there is only one place in the core DMZ where automatic pluralizing if the model cannot be avoided — in determining the relationship table name of self-relationship.

It might work; if it doesn't work, I cannot provide support. You'll have to dig into the source code to understand it. Sad


[Deprecated] DMZ 1.5.4 (DataMapper OverZealous Edition) - El Forum - 11-06-2009

[eluser]The Mask[/eluser]
Hello chaps,
Is it possible to execute any valid sql using a datamapper model? I have a secret admin option on my site where I can enter any SQL to query a table, perform updates, deletions etc.
So, I may for example enter 'select * from users' or 'select * from groups' or 'delete from user where id = 123' etc...

How can I execute this SQL using Datamapper?

Before converting my site to use Datamapper, I was using:
$query-> = $this->db->query( $this->input->post( 'sql ' ) );
$result = $query->result_array();
And then in the view, displayed the rows/columns in array $result.

I was thinking I could use the Utility method but looks like this is restricted to querying the table the model is based on.
i.e. $u = new User;
$u->query( 'select * from users' ) would work
but $u->query( 'select * from groups' ) wouldn't?

Any ideas?