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]
  • #781 / Dec 26, 2010 2:45pm

    MelloMike

    3 posts

    Hi matyhaty! Thanks for the quick reply.. I had to change get() to get_iterated() and it worked… only problem is that it’s just returning all the images but not actually associating them with the correct model.

    so I can’t use something like this after I use that code..

    foreach($u as $user)
    {
        echo $user->profile-image->all_to_array();
    }

    The above will return ALL the images for every profile inside of the first $user->profile->all_to_array(); ... the rest will be empty.

  • #782 / Dec 26, 2010 3:26pm

    anaxamaxan

    16 posts

    @MelloMike I made that mistake with include_related too, but include_related and deep relationships only work along one-to-one relationships.  You’ll need to call get() on each Profile instance to access the related images.

  • #783 / Dec 26, 2010 3:28pm

    MelloMike

    3 posts

    @MelloMike I made that mistake with include_related too, but include_related and deep relationships only work along one-to-one relationships.  You’ll need to call get() on each Profile instance to access the related images.

    Awwww, thats a bummer.. but thanks. At least I know what I have to do now.

  • #784 / Dec 26, 2010 6:54pm

    WanWizard

    4475 posts

    Having include_related() work on has_many is on the todo list, but it won’t be in time for the next release (due in the next couple of days).

  • #785 / Dec 28, 2010 1:28am

    Haqqi

    15 posts

    Update: Sorry, my fault. I should use update() method instead of save().

    I downloaded latest source of DataMapper from Bitbucket.

    What I want to ask is how to ignore created and updated field? Because not all my tables have created and updated fields. If i just try to write:

    $opt = new Option();
    $opt->get_by_key('the_key');
    $opt->value = 'new_value';
    $opt->save();

    I got an error that DataMapper try to update “updated” field. I have changed the config item “updated_field” to “null”, but it seems that DataMapper use default “updated” as the name of the field.

  • #786 / Dec 29, 2010 4:08pm

    WanWizard

    4475 posts

    Should work with save() as well.

    I’ve found the problem, I’ll update it on bitbucket later today.

  • #787 / Dec 30, 2010 5:18pm

    Guido Mallee

    14 posts

    Hi,

    I’m new to DMZ but finding some trouble combining DMZ with the structure I use to mantain in my databases.

    That’s because I add an ‘active’ field to every table in my DB. When I want to delete a record from a table, I never really delete it, but set the active field of that record to FALSE.

    I know this method has it’s advantages and disadvantages, but so far I’ve never regret that I started using this consequently.

    Of course it’s possible to keep using this method in DMZ, though i would like this to be applied by default on methods like get() and delete().

    Will I have to write my own extension or will I be reinventing the wheel?

    Many thanks!

  • #788 / Dec 31, 2010 6:59am

    WanWizard

    4475 posts

    Datamapper is just a class, and as such, it can be extended.

    Overload the get() and delete() methods to deal with your active field. For get(), you could just include a where clause including ‘active’, delete should require more attention as it deals with deleting relationships as well.

  • #789 / Dec 31, 2010 10:05am

    Guido Mallee

    14 posts

    Thanks! I’ll dig in to that then..

  • #790 / Dec 31, 2010 3:40pm

    Guido Mallee

    14 posts

    Something else:

    I’m busy porting one of my CI projects to work with DataMapper. Seemed to be going fine untill i got this php error:

    Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 40961 bytes) in C:\xampp\htdocs\spzw\system\core\Loader.php on line 665

    Also when I output my $data variable, that I pass to my view, with FirePHP, it seems to be huge (lot’s of data I do not use)! And of course, the page loads very slow (ending up with the above error).

    Is there a commonly made mistake that could cause DataMapper use so much memory?

    Thanks!

  • #791 / Jan 01, 2011 10:54am

    WanWizard

    4475 posts

    Your reading all results into memory. Since every record is an object, this can consume lots of memory if you have a lot of records in the result set.

    In general:
    - if you need the results to iterate over them (like with a foreach), use get_iterated() instead of get() (see the manual).
    - if you don’t need all these individual results, rethink your query. Lots of rows in a result is an indication of a sub-optimal query.

  • #792 / Jan 02, 2011 3:43pm

    Guido Mallee

    14 posts

    Strange thing is that there aren’t many records in the result set. Anyway, seems like the problem occured because of the way i passed a DM object to a subview. I did:

    <?php foreach ($page->block as $block): ?>
    <?php $this->load->view('block', array($block)); ?>
    <?php endforeach; ?>

    I solved it by doing:

    <?php foreach ($page->block as $block): ?>
    <?php $this->load->view('block', $block); ?>
    <?php endforeach; ?>

    Seems to be working fine now.

    I’m in doubt about something else though. Is there a more efficient way to write the following piece of code?

    $data['page']->block->get();
    foreach ($data['page']->block as $block)
    {
        $block->block_type->get();
        $block->block_text->get();
    }
  • #793 / Jan 02, 2011 6:13pm

    Guido Mallee

    14 posts

    Another thing i’m about in doubt, is how to deal with extra attributes in a joining table. For example:

    I have the table PAGES and the table BLOCKS. These tables have a many to many relationship. Now in the joining table BLOCKS_PAGES i have a attribute ‘position’ which defines the position of a block in a page.

    How to easily get all blocks of a certain page, ordered by position, and how to add a block to a page defining the position?

    Thanks!

  • #794 / Jan 03, 2011 6:52am

    WanWizard

    4475 posts

  • #795 / Jan 03, 2011 7:26am

    Guido Mallee

    14 posts

    Thanks! I must have missed this article in the manual. Sorry for the inconvenience.

    Any thoughts on the piece of code in my other post? It’s like this: I have the tables A, B and C. A has many B. B has one C. How to load the complete resultset in an object? Do i have to loop over the resultset B, to get C for each result, as in my example? Or can it be done easier?

    I tried to set auto_populate_has_many and auto_populate_has_one to TRUE in the DM config file. Though, this makes A automatically get all B’s, but doesn’t make B get C.

    I couldn’t find in the manual. Please forgive me if it’s in there!

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

ExpressionEngine News!

#eecms, #events, #releases