CodeIgniter Forums
DataMapper 1.6.0 - 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: DataMapper 1.6.0 (/showthread.php?tid=11358)



DataMapper 1.6.0 - El Forum - 02-14-2009

[eluser]OverZealous[/eluser]
Ahh - I didn't think about the auto transaction issue. I handle all of my transactions by hand.

I'll update that on my development version. Thanks for finding the bug!


DataMapper 1.6.0 - El Forum - 02-14-2009

[eluser]dobomode[/eluser]
You are welcome. :-)
Do you think that the auto transaction mechanism could have an impact on any of the other functions of datamapper?

By the way, what are the benefits of enabling auto transactions?


DataMapper 1.6.0 - El Forum - 02-14-2009

[eluser]OverZealous[/eluser]
I don't have the answers to that one (DataMapper is not my code - I just hack on it ;-))

I do transactions by hand because I'm usually saving multiple objects, and I need all to succeed or all to fail (and I use PostGreSQL). Oh, and I'm used to it.

That being said, I doubt that you'll see too many other issues with the auto transaction mechanism.


DataMapper 1.6.0 - El Forum - 02-15-2009

[eluser]DominixZ[/eluser]
I have one suggest that I think DataMapper should have that is "Get_array_result". it will be nice to use with json_encode. That would be easy to do that today i must convert data from DataMapper to array and use json_encode that isn't nice


DataMapper 1.6.0 - El Forum - 02-15-2009

[eluser]OverZealous[/eluser]
While I wouldn't add that in to DataMapper directly*, if this is something you need, you could add it to a DataMapper extension class, and then extend this class instead (which I do for a lot of my code).

The code could be really simple:
Code:
// untested
function get_array_result($limit = NULL, $start = NULL) {
    $this->get($limit, $start);
    $result = array();
    foreach($this->all as $item) {
        $item_values = array();
        foreach($this->fields as $field) {
            $item_values[$field] = $item->{$field};
        }
        $result[] = $item_values;
    }
    return $result;
}

Add this to your own extension of DataMapper, and then use that as the base class for your models. I highly recommend this anyway, because there are always going to be features that you want in all of your models, but might not fit in with the DataMapper core design. (I created a new model called DataMapperExt in the Models folder. It shouldn't ever be instantiated directly, but use it as the base class for all your other models.)

* I wouldn't add it to the general distribution because the $item->all array provides the same basic features, and I think it would confuse the correct way to use DataMapper.

Obviously, you can't use json_encode() with the ->all array, for a variety of reasons, but I also don't think you necessarily want to send every field within an object over JSON every time. For my code, I have dedicated classes I use to manage my JSON responses, and I use these to handle the conversion, so I can specify which fields to send.


DataMapper 1.6.0 - El Forum - 02-16-2009

[eluser]DominixZ[/eluser]
Thanks for code and reason. Smile


DataMapper 1.6.0 - El Forum - 02-16-2009

[eluser]Matthew Lanham[/eluser]
What's in the pipeline for further developments for DataMapper, although it's working great i'd love to see it keep going as i think it's a fantastic library, is someone still maintaining it?


DataMapper 1.6.0 - El Forum - 02-16-2009

[eluser]OverZealous[/eluser]
@Matthew Lanham

I can't speak for stensi - it is his project after all - but if you look just a few posts back, you'll see I am working on extending the project. So far, several of my modifications to DataMapper have worked their way into the actual project, including the where_related() methods.

I've already mostly developed has_one relationships that don't require a join table. I've added more advanced relationship capabilities, that allow multiple-relationships to the same object without separate classes (ie: tracking an editor and a creator) - however, they might be a bit confusing right now. I also added the ability to "join" the results from several tables directly into DataMapper.

stensi is still the maintainer, and the owner of the project. I don't think I have the ability to maintain it as well as he has.


DataMapper 1.6.0 - El Forum - 02-16-2009

[eluser]GregX999[/eluser]
Hey guys,

I'm trying to use a password confirmation in my sign-up form and I'm having trouble getting the error message working if it doesn't match your password. I don't have a "confirm_password" field in my database table - I shouldn't need one right? My other errors work fine.

I always get this error in my list of form errors (any errors generated by data not passing validation... ie: "The Email field is required"):
"Unable to access an error message corresponding to your field name."

And I get this error:
Undefined property: stdClass::$confirm_password
when I try to access "User->error->confirm_password".
(See my HTML below)


Here's what I have in my validation array:

array(
'field' => 'password',
'label' => 'Password',
'rules' => array('valid_password', 'required', 'trim')
),
array(
'field' => 'confirm_password',
'label' => 'Confirm Password',
'rules' => array('matches' => 'password')
),

Here's my HTML:
($form_errors is set to $user->errors, $user being my User object)

<div class="field_row">
&lt;?= form_label('Choose a Password', 'password'); ?&gt;
&lt;?= form_password(array('name' => 'password', 'value' => set_value('password'), 'class' => 'field' . $form_errors->password ? ' error' : '')); ?&gt;
</div>
<div class="field_row">
&lt;?= form_label('Confirm Password', 'confirm_password'); ?&gt;
&lt;?= form_password(array('name' => 'confirm_password', 'value' => set_value('confirm_password'), 'class' => 'field' . $form_errors->confirm_password ? ' error' : '')); ?&gt;
</div>


Any advice?

Greg


DataMapper 1.6.0 - El Forum - 02-16-2009

[eluser]OverZealous[/eluser]
I have to assume you have a typo in your class. There's nothing wrong with your code you posted, however, the only way I can see that you would have the second error (undefined property) is if the field 'confirm_password' was not properly set on the fields array. DataMapper sets the error value for every field to '' when it starts.

The first error would only occur if the 'password' field is completely empty. If it is empty, you cannot save to the database, since you marked it as required. If you are trying to save an existing user, but don't want to change the password, you'll want to ->get_by_id($id) on the existing user, change the changed fields, and then re-save the user.