Welcome Guest, Not a member yet? Register   Sign In
[Deprecated] DMZ 1.6.2 (DataMapper OverZealous Edition)

[eluser]NachoF[/eluser]
This question is not related to the new RC but just in general.. regarding validation errors

how do you get the specific field error of a related field??

for instance, Group has validation on User

but

Code:
echo $user->error->group;

gives me

Quote:Message: Undefined property: stdClass::$group

[eluser]OverZealous[/eluser]
@NachoF

Two things are happening. First, there is no error (in your example) for that field.

Second, there is a bug (in some sense) in that the related items aren't set to '', leading to the error. I'll look into fixing it before the release of 1.7

So, a short term fix is to use isset() before echoing them. Smile

Update: That was easy. If you want to manually fix 1.6.2, just go to the clear() method, and add this line to each of the $has_one and $has_many foreach loops:
Code:
$this->error->{$related} = '';

[eluser]NachoF[/eluser]
And where can I find the clear() method?

[eluser]OverZealous[/eluser]
@NachoF
In the DataMapper library. It's called Edit / Find, search for function clear.

[eluser]NachoF[/eluser]
Code:
function clear()
    {
        // Clear the all list
        $this->all = array();

        // Clear errors
        $this->error = new stdClass();
        $this->error->all = array();
        $this->error->string = '';

        // Clear this objects properties and set blank error messages in case they are accessed
        foreach ($this->fields as $field)
        {
            $this->{$field} = NULL;
            $this->error->{$field} = '';
        }
        
        // Clear the auto transaction error
        if($this->auto_transaction) {
            $this->error->transaction = '';
        }

        // Clear this objects "has many" related objects
        foreach ($this->has_many as $related => $properties)
        {
            $this->error->{$related} = '';
            unset($this->{$related});
        }

        // Clear this objects "has one" related objects
        foreach ($this->has_one as $related => $properties)
        {
            $this->error->{$related} = '';
            unset($this->{$related});
        }

        // Clear the query related list
        $this->query_related = array();

        // Clear and refresh stored values
        $this->stored = new stdClass();

        $this->_refresh_stored_values();
    }

Thats the method... Im still getting the same error

[eluser]OverZealous[/eluser]
@NachoF
Then you don't have a <a href="http://www.overzealous.com/dmz/pages/troubleshooting.html">relationship named "group" on the User object</a>. I can't think of another reason.

[eluser]NachoF[/eluser]
I do have it.. in fact. If I force the form to have the error then it will display the error... weird.

[eluser]OverZealous[/eluser]
@NachoF
Oops. I found it. It's in the validate method. Similar problem. I'll fix it now. This one won't be as simple, though.

[eluser]NachoF[/eluser]
Its not critical though.. using isset seems to work

[eluser]OverZealous[/eluser]
@NachoF
It's actually a great find because I've come up with a better solution than previous.

I've replaced the generic stdClass error object with a custom class. This class automatically returns the empty string for any field, so this error could never happen. It also has better documentation, so code completion will work to show the common options (string, all, transaction), as well as hinting for the field names.

Another benefit is there is no need to set an empty string for every field anymore, (microscopically) reducing memory usage. This all fits really well with the purpose of the 1.7 update (which is performance and cleanup).

Thanks for finding it!




Theme © iAndrew 2016 - Forum software by © MyBB