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

[eluser]mcnux[/eluser]
[quote author="OverZealous" date="1249716403"]@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.[/quote]
My bad! Sorry.

[eluser]pdswan[/eluser]
@OverZealous

A thought on custom validation and error messages:

I'm writing a custom validation function that uploads a file so the error message it generates on failure needs to be relatively dynamic. instead of defining the error message in the language file I am setting it manually using $object->error_message.

This effectively sets the error message, but also results in an extra error message of 'Unable to access an error message corresponding to your rule name: attempt_upload.'

I'm thinking custom error messages might frequently need to be more dynamic than what the language file setup allows for so it might be good to not include that error message?

Then again, there's probably merit to the argument that the file uploading logic shouldn't be part of a validation function.

Anyway, just a thought.

[eluser]tdktank59[/eluser]
Hey is there any way to add a value before a dropdown such as a "== Select A Value ==", or "== All Users =="
Or something along those lines would be awesome!

[eluser]OverZealous[/eluser]
[quote author="pdswan" date="1249940900"]This effectively sets the error message, but also results in an extra error message of 'Unable to access an error message corresponding to your rule name: attempt_upload.'[/quote]

This is another left-over flaw. I'll look into it. I think what I'd rather do is have the method return a string for custom error messages, TRUE for success, and FALSE for default error messages. Then you wouldn't have to set it manually.


[quote author="tdktank59" date="1249948218"]Hey is there any way to add a value before a dropdown such as a “== Select A Value ==”, or “== All Users ==”
Or something along those lines would be awesome![/quote]

Yes, but you have to override list when setting up the form. It looks something like this:
Code:
$g = new Group();
$g->get();
$group_list = array(0 => '-- All Users --');
foreach($g->all as $group) {
    $group_list[$group->id] = (string)$group;
}

echo $u->render_form(array(
        ....
        // We want to limit the groups visible
        'group' => array(
            'list' => $group_list
        )
        ....

I might eventually look into providing a custom option for the first row.

[eluser]tdktank59[/eluser]
Thats a little too much out of my way to do it that way. Im loading up 5 drop-downs that all need these types of options...

Guess ill get on my way to hacking the code to add this functionality...

Ill post it up once I get it working.

[eluser]OverZealous[/eluser]
[quote author="tdktank59" date="1249953004"]Thats a little too much out of my way to do it that way. Im loading up 5 drop-downs that all need these types of options...[/quote]

Well, I don't think it's that much work. If you were doing this the old way it would be way more work than even that.

You don't have to hack it, anyway. Just write your own drop-down method. As long as it is named input_mymethod, and available, you can write your own code. You can easily write it to simply add the first row to the list, then pass everything back to the HTMLForm class.

[eluser]OverZealous[/eluser]
[quote author="pdswan" date="1249940900"]This effectively sets the error message, but also results in an extra error message of 'Unable to access an error message corresponding to your rule name: attempt_upload.'[/quote]

Well, I feel stupid %-P

The (current) correct way to set a custom error message without getting the extra "not found" message is to return TRUE or return nothing. If you set an error message, the validation routine will fail.

The drawback to this is that the rest of the validation tests are still run.

So, I'm still going to try out adding the ability to return a string to cause a validation to fail while setting a custom error message. For now, though, just don't return anything (or return true), but go ahead and set the custom message.

[eluser]sethbaur[/eluser]
I'm trying to use include_related twice to get related fields from two different related objects. When I do this it seems that the second include_related overrides the first. Is there any way to make this work the way I want or am I doing something wrong?

Code:
$updates = new Update();
$updates->order_by('created', 'DESC');
$updates->include_related('uri', array('uri_string'));
$updates->include_related('section', array('title'));
$updates->get($per_page);

[eluser]OverZealous[/eluser]
include_related doesn't overwrite - you can use it as many times as you want. You can even call the same data - it doesn't keep track. It only protects the original fields for the main object from being overridden.

Are you sure that 'uri' works on its own? Have you output the query? I am guessing it's a configuration problem.

[eluser]mcnux[/eluser]
Think I'm missing something obvious (again). I would like to perform an aggregate query, like so...

Code:
SELECT
  month,
  COUNT(myInt) myCount
FROM
  myTable
GROUP BY
  month

... using the query builder. I can't seem to do it without hacking about a bit:

Code:
$myTable->select('month')->select_sum('IF(1,1,0)','myCount')->group_by('month');

I'd like to do something like:
Code:
$myTable->select('month')->select_count('myInt','myCount')->group_by('month');

as select_sum(IF(1,1,0)) is a tad nasty! I can't even do select_sum('1'), which I think would be acceptable, as the query builder thinks, as it should, that '1' is a field name and thus wraps it with ticks (`) - hence the IF(1,1,0).

Hope I'm being stupid!




Theme © iAndrew 2016 - Forum software by © MyBB