ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

DMZ 1.7.1 (DataMapper OverZealous Edition)

March 14, 2010 11:43pm

Subscribe [104]
  • #376 / Jun 27, 2010 1:22pm

    OverZealous

    1030 posts

    @lexusgs430
    This is not a DMZ issue.

    See the Troubleshooting Guide for suggestions.

  • #377 / Jun 27, 2010 7:00pm

    lexusgs430

    49 posts

    Ok so I was making changes to one of my models, and then all of the sudden I get 503 service error on any page I try to access. I contact my webhost they tell me its definitely my making changes to the code. But I undid what I did (I was adding a new relationship in the model, so I deleted it.)—but still nothing works any idea what could be causing it or how I could fix it?

  • #378 / Jun 27, 2010 7:05pm

    lexusgs430

    49 posts

    actually got it figured out, of course it took me an hour to figure it out, but not until immediately after asking for help after that hour passed.. problem was I was self referencing a model in a model I must have made changes to thinking it was the controller. sigh.

  • #379 / Jun 28, 2010 3:35pm

    lexusgs430

    49 posts

    sorry for so many questions so quickly 😊

    Having trouble formatting a count distinct query, was hoping you could shed some light.

    Im calling the following within a result array.

    $i = new Item();
        $itemCount = $i->where('style_id', $result->id)->count();
        $sitesCount = $i->where('style_id', $result->id)->count_distinct('site_id');

    The itemCount works fine. The sitesCount just returns the same as itemCount, even though there usually maybe half the number of distinct site_ids for each particular result. Im sure Im just formatting it wrong but Im having trouble figuring out exactly how to format it.

  • #380 / Jun 28, 2010 3:41pm

    OverZealous

    1030 posts

    @lexusgs430
    First, you are using the method wrong.  Read the docs again.  The first parameter is the list of IDs to exclude.  The second parameter is the column to use DISTINCT on.

    Before submitting a question, you should look at the queries being generated.  There’s some good tips for debugging in the troubleshooting guide, at the top.  They walk you through some basic debugging steps.  You probably would have easily seen that the query being generated was not what you expected.

  • #381 / Jun 28, 2010 4:00pm

    lexusgs430

    49 posts

    cool, will do, thanks for the help

    @lexusgs430
    First, you are using the method wrong.  Read the docs again.  The first parameter is the list of IDs to exclude.  The second parameter is the column to use DISTINCT on.

    Before submitting a question, you should look at the queries being generated.  There’s some good tips for debugging in the troubleshooting guide, at the top.  They walk you through some basic debugging steps.  You probably would have easily seen that the query being generated was not what you expected.

  • #382 / Jun 30, 2010 2:10am

    Tom Vogt

    49 posts

    I’m trying to use count(*) and group_by together and can’t figure out how to do that using DMZ.

    In SQL, what I want to do is roughly this:

    SELECT count(*), some_field, AVG(other_field) FROM table WHERE group_id = 1 GROUP BY some_field;

    now I came as far as

    $this->table->group_by('some_field')->select('some_field')->select_avg('other_field')->get();

    which gives me everything but the count. Then I thought doing

    foreach ($this->table as $x) {
       $count = $x->count();
    }

    would work, but it gives me the total numbe of results, not the individual count for each row. Someone got a better idea for the DMZ equivalent of the SQL I posted above?

  • #383 / Jun 30, 2010 9:19am

    OverZealous

    1030 posts

    @Tom Vogt
    CodeIgniter’s ActiveRecord (and therefore DMZ) is missing select_count().  So there’s no super-easy way to do this.  However, there is a fairly simple way:

    $object
        ->select_func('count', '*', 'count')
        ->select('some_field')
        ->select_avg('other_field')
        ->group_by('some_field')
        ->get();

    This should get you what you want, although I haven’t tested it.  I have it on the list to add select_count to DMZ.

  • #384 / Jun 30, 2010 9:26am

    Tom Vogt

    49 posts

    Does exactly what I want, fantastic. I read about select_func() but didn’t realize I could use it for count(*). Thanks a lot!

  • #385 / Jun 30, 2010 4:17pm

    anveo

    2 posts

    Is there a way I can access the list of returned objects via an index number? i.e.

    $users = new User();
    $users->get();
    
    $first = $users[0];

    I see DataMapper implements IteratorAggregate, and defines the ‘key’ function, but I can’t seem to get it working. I am subclassing DataMapper as DataMapperExt, and calling the parent __construct, but I see DataMapper does both __construct and DataMapper() constructor. Might that have something to do with it?

  • #386 / Jun 30, 2010 4:54pm

    jpi

    55 posts

    I am not sure, but maybe try :

    $users = new User();
    $users->get();
    
    $first = $users->all[0];
  • #387 / Jun 30, 2010 5:07pm

    OverZealous

    1030 posts

    @anveo
    jpi is correct.  When I decided that the iterator method was going to be the default way to access results, I removed a lot of the references to the ->all array in the docs.

    I need to put them back in on the basic get page, so that they are easier to find.

    Basically, a non-get_iterated get() sets the results on the ->all array.  The iterator aggregate simply looks at this array.  If you use get_iterated, however, some magic is done to prevent the objects from being configured unless they are needed.

    (Thanks, jpi, for providing support!)

  • #388 / Jun 30, 2010 5:18pm

    anveo

    2 posts

    I am not sure, but maybe try :

    $users = new User();
    $users->get();
    
    $first = $users->all[0];

    Thanks! Works great.

  • #389 / Jun 30, 2010 6:55pm

    NachoF

    171 posts

    @NachoF

    I don’t know what to tell you.  If you set the field to an empty string, then DMZ has to assume you want to save it.  An empty string is not a NULL, and when inserting new data, DMZ only excludes NULLs from the query.

    The best solution is to not set fields you want to be NULL to an empty string.

    But how exactly do I do that??.. there is a bunch of text fields in my form.. and the user should be able to write on whichever he chooses to… Basically, those fields should be numeric but NOT required.

    I would like to keep my controller action as clean as possible (which is why im using your array extension and In only doing)

    $object->from_array($_POST);
     if($object->save())
    {
    redirect ("home");
    }

    could chainging the data type in the database to character varying but keeping the numeric validation rule in datamapper be a good approach?

  • #390 / Jun 30, 2010 10:03pm

    OverZealous

    1030 posts

    @NachoF
    DMZ provides all of the tools - but you still have to make the application.  Like I said, there’s no way for DMZ to know the difference between “empty string that is supposed to be NULL” and “empty string that is supposed to be an empty string”.

    If you want to accept values that need to be modified, use validation rules.  That’s what they are there for.

    In my case, for different reasons, I added a null_on_empty rule to my base class.  It looks something like this:

    function _null_on_empty($field) {
        if(empty($this->{$field})) {
            $this->{$field} = NULL;
        }
    }

    You can also make that an extension.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases