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.

[Deprecated] DMZ 1.6.2 (DataMapper OverZealous Edition)

November 23, 2009 11:54pm

Subscribe [46]
  • #46 / Dec 11, 2009 2:05pm

    OverZealous

    1030 posts

    @BrianDHall

    If all you want is the items - not the carts they are related to - you can do this:

    $listings = new Listing();
    $listings->where_related('cart_item/user', $user)->get();

    This gets all listings related through a cart item to a user.  This assumes that there is only one user per cart_item, and one cart_item per listing.  If you have multiple in either case, then you need to add a distinct into your query.

    If you also want the (singly-related) cart_item, you can do that in one query as well, like so:

    $listings = new Listing();
    $listings->include_related('cart_item', '*', TRUE, TRUE);
    $listings->where_related('cart_item/user', $user)->get();
    
    foreach($listings as $listing) {
        echo $listing->cart_item->id;
    }

    Both functions are detailed on Get (Advanced).

  • #47 / Dec 11, 2009 2:06pm

    OverZealous

    1030 posts

    @cube1893

    Even simpler than Mirage’s suggestion, I think you have the default value for the column set to 0.  You should check the table settings (in MySQL) and make sure the default value is NULL.

  • #48 / Dec 11, 2009 2:16pm

    cube1893

    18 posts

    @Mirage
    Thanks for your solution, it works!

    @OverZealous
    Thanks, but the default value is set to NULL. If I insert the data via phpmyadmin, it works. It’s a pity, because I would be nice if DMZ would convert empty input fields to NULL, if this ist set in the table settings.

  • #49 / Dec 11, 2009 2:20pm

    Mirage

    273 posts

    Something else I’m grappling with on my many-to-many relations.

    As you know I’ve worked up this magnificent MPTT extension. On simple relations all that’s needed to use it is a lft and rgt column in the table. I’m trying to find a way to make this extension work on a join table.

    Since join tables don’t create their own objects, it’s not clear to me if or how this is possible at all.

    I could see creating an independent model that works against the join table perhaps. But it’s unclear to me how I would reference objects in the relation.

    Basically the task is to keep items in the join table in a fixed order.

    Ideas?
    -m

  • #50 / Dec 11, 2009 4:21pm

    OverZealous

    1030 posts

    It’s a pity, because I would be nice if DMZ would convert empty input fields to NULL, if this ist set in the table settings.

    There’s no way for DMZ to know what the default value is on a column.  So, it sets the column to whatever you ask it to.  (And ‘’ is not the same as NULL, since NULL is a special data construct.)


    @Mirage
    By definition, a join table is not a model or an object.  It’s just the link between two objects.  That’s why you can’t create an object out of it.

    I don’t see any way to implement the MPTT structure via the internal relationship code.  I’m not even 100% sure what the benefit would be.

  • #51 / Dec 11, 2009 4:38pm

    cube1893

    18 posts

    It’s a pity, because I would be nice if DMZ would convert empty input fields to NULL, if this ist set in the table settings.

    There’s no way for DMZ to know what the default value is on a column.  So, it sets the column to whatever you ask it to.  (And ‘’ is not the same as NULL, since NULL is a special data construct.)

    Alrighty, I realised my error in reasoning, thanks!

  • #52 / Dec 11, 2009 5:39pm

    Mirage

    273 posts

    By definition, a join table is not a model or an object.  It’s just the link between two objects.  That’s why you can’t create an object out of it.

    I don’t see any way to implement the MPTT structure via the internal relationship code.  I’m not even 100% sure what the benefit would be.

    Ok, so I do get that. But that doesn’t mean I couldn’t make a model anyway representing the join-table if only to be able to apply MPTT, right?

    Another alternative to that would to add some methods in one of the related models to handle this, or even straight SQL in the controller.

    What would your approach be? Make a Model and ride with it the DMZ way, or use a less structured approach?

    TIA,
    m

  • #53 / Dec 11, 2009 5:51pm

    OverZealous

    1030 posts

    I’m not 100% sure what you are asking, Mirage, but I have a recommendation in the docs for a different problem that sounds like what you are asking about.

    Maybe that will give you some help!

  • #54 / Dec 11, 2009 11:54pm

    tdktank59

    322 posts

    Hey Phill got a question.

    So ive got 3 tables
    users
    user_info
    user_settings

    However I want to only have 1 page for all the settings that can change.
    is there a way to be able to save all (the second 2 tables are a one to one relation with users.)

    Otherwise ill end up having a few screens to set all the details, but would be nice to do it with the array and form extensions if possible.

    I have no problem setting in the main model all the values for the form, just saving them is the issue.

  • #55 / Dec 12, 2009 12:05am

    OverZealous

    1030 posts

    The HTMLForm extension isn’t designed to handle multiple objects.  It’s a simple scaffolding-like extension.  If you want to manipulate multiple objects, you’ll have to manually build the form, or extend or customize the HTMLForm class.

    You can save the data using the Array extension, but only if there are no name collisions.  I don’t see what the problem is here — just specify the fields and save the objects.

    If you want something more complex, then you’ll just have to manually create it or manually save it.

    The extensions in DMZ are closer to examples than be-all-end-all solutions.

  • #56 / Dec 12, 2009 12:09am

    tdktank59

    322 posts

    fair enough was just currious if you have an idea

  • #57 / Dec 12, 2009 12:38am

    Mirage

    273 posts

    I probably wouldn’t use the form extension for this. In general I’m not a big fan of form generators.

    So I’d build the form manually and use php array notation to avoid conflicts and then use the array extension to import the resulting sub-arrays in $_POST to the proper objects, followed by $user->save($info,$settings).

    hth,
    -m

  • #58 / Dec 12, 2009 12:42am

    tdktank59

    322 posts

    I probably wouldn’t use the form extension for this. In general I’m not a big fan of form generators.

    So I’d build the form manually and use php array notation to avoid conflicts and then use the array extension to import the resulting sub-arrays in $_POST to the proper objects, followed by $user->save($info,$settings).

    hth,
    -m

    Thats what Ill probably end up doing.
    I also dont mind the form generator since all of my forms are basically the same with small variations and I don’t need anything fancy on them.

    However the other option is I extend the form extension and add the functionality I need (multidimensional array support or something)

  • #59 / Dec 13, 2009 11:01pm

    teddy3

    3 posts

    hi,

    i set Multiple Relationships to the Same Model

    like on http://www.overzealous.com/dmz/pages/advancedrelations.html

    How can I get a list of users and get related post of each user which related as creator?

  • #60 / Dec 15, 2009 2:48am

    chadbob

    11 posts

    Can someone help me figure out how to sort results by a related count?

    I have a crime, and report.  They have a many-to-many relationship.


    I can get all the statutes and the number of reports tied to each statute by:

    $this->load->model('statute');
    
    $s = new statute();
    $s->get();
    
    foreach($s->all as $t){
        
    $t->report->get();
    $t->description;
    $t->report->count();
    
    }

     

    How would I sort the results of statutes by number of reports related?  Let’s say I just wanted the top 5 statutes by # of reports?

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

ExpressionEngine News!

#eecms, #events, #releases