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.

DataMapper 1.6.0

September 05, 2008 12:32pm

Subscribe [115]
  • #61 / Oct 02, 2008 4:56am

    Isuka

    24 posts

    Thanks for your response stensi. In fact I’m doing error validation (my error messages are on the view). But when I submit my form, its return TRUE, so I don’t have errors. That’s the weird thing, all my others fields are updated correctly, only the “is_published” field is not updated. And the same thing happen if, for exemple, I fill my “lastname” field width a 0, save() return TRUE but nothing updated in my database. I think that the save() method don’t want a value of 0.

  • #62 / Oct 02, 2008 5:51am

    Iverson

    153 posts

    Thanks. I was going in the direction of the third example but I couldn’t quite get the syntax and call right. I think that is the best solution, seeing that #1 would put all your errors in one place, and there’s no way to know which ones to echo, unless you’re going to tell me that it would just be an empty string. If that’s the case, that would be perfect, since I like to do client-side validation as well.

  • #63 / Oct 02, 2008 6:45am

    stensi

    109 posts

    @Isuka: Ah, I see.  Thanks for pointing that out!  In the _to_array() method, it ignores a property value if it is considered empty(), which a 0 is.  I’ll fix it up, run some tests, then have version 1.3.2 up soon.

    @Iversion: Yep, for #1, if there were no errors it’ll just be an empty string.  You can still go with any of the 3 ways as it does an empty string for each thing if its corresponding property had no errors.

  • #64 / Oct 02, 2008 6:58am

    Isuka

    24 posts

    Great. Another little thing I have noticed. If I make validation rules like this :

    var $validation = array(
        array(
                'field' => 'lastname',
                'label' => 'Nom',
                'rules' => array('required')
            ),
            array(
                'field' => 'firstname',
                'label' => 'Prénom',
                'rules' => array('required', 'matches' => 'lastname')
            )
    );

    My error messsage will look like this :

    Le champ Prénom doit correspondre au champ lastname

    Is it possible to get the label value (“Nom”) instead of the field value (“lastname”) ?

  • #65 / Oct 02, 2008 7:20am

    stensi

    109 posts

    Version 1.3.2 has been released!

    View the Change Log to see what’s changed.

    In short, I fixed the _to_array() method so it returns all properties (including zero, NULL and empty strings) except when getting by objects properties ($object->validate()->get()) so you can now save zero’s, NULL’s and empty strings.  I also corrected validation error messages to show the label if a field name is used as a parameter.

    @Isuka: That’s something I’ve noticed as well, and am working to rectify.  I’ll look at it tomorrow if I have the time.  I’m a bit short on it tonight and don’t want to rush a hacky fix on that one, since I want to solve that sort of issue for any validation rule, not just the ‘matches’ rule.

    UPDATE

    I fixed the matches rule thing Isuka mentioned and have bundled it into 1.3.2.

  • #66 / Oct 02, 2008 7:32am

    Isuka

    24 posts

    I have just install datamapper 1.3.2 and it seems there is a problem with the get() method. When I loop through $obj->get()->all, all my ID field are the same. Sorry to give you some work again 😊

  • #67 / Oct 02, 2008 7:41am

    stensi

    109 posts

    I had a brainstorm on how to fix that “matches” error thing so I just bundled it into version 1.3.2.

    As for getting the same ID for everything, you’re probably not using the right object in your foreach loop.  I just did a clean install of DataMapper and ran all the example code and everything works correctly.

    Can you post your code so I can have a look?

  • #68 / Oct 02, 2008 8:41am

    Isuka

    24 posts

    You are right, my old model class was loaded in my controller, making some conflict :red:

    I think there is the same problem of the empty value for the get() method. My field “is_published” is now updated correctly with a 0 but when I do a $obj->get(), $obj->is_publish is empty.

  • #69 / Oct 02, 2008 9:37am

    stensi

    109 posts

    Ah, sorry.  I should’ve noticed a similar change would be required in the _to_object() method.  Could you redownload version 1.3.2 and try again?  I just bundled the fix for that into it.

  • #70 / Oct 02, 2008 10:03am

    Isuka

    24 posts

    It works fine now 😊

    Just one more thing, I can’t make work xss_clean in my validation rules. When I put this rule I got a fatal error :

    Fatal error: Call to a member function xss_clean() on a non-object in applications/backend/models/datamapper.php on line 1853

    All others rules work great except this one.

  • #71 / Oct 02, 2008 12:21pm

    GregX999

    39 posts

    Hey, I haven’t been able to play with the new version very much yet - too much other work… :(

    But soon!!

    Also, I just wanted to say “Don’t forget to update the docs.” - if you haven’t already updated them that is (these ones: http://stensi.com/datamapper/pages/toc.html). One reason I’m really liking both CI and DM is because of the excellent online docs with loads of examples. Be sure you keep those docs up to date for people just finding DM and wanting to see how it’s used. I know it sucks writing docs when you could be improving the code, but without those docs, I wouldn’t have even given DM much of a look at all.

    (Thanks for the mention in the credits… totally unnecessary, but thanks!)

    Greg

  • #72 / Oct 02, 2008 3:26pm

    hugslife

    8 posts

    second that, your docs are very good, which is to say that
    they don’t look like they were written by a coder 😊

    one thing i keep banging my head against, and it’s probably
    that i’m just thick or doing things bass ackward,
    is iterating over an “open ended” list. Say I wanted a list
    of the books in my inventory, including JOIN’d authors names.
    given tables AUTHORS, BOOKS, and AUTHORS_BOOKS:

    $b = new Book; 
    
    foreach ($p->book->get()->author->get()->all as $items) {
    
    echo "ISBN: " . $items->book->isbn . "
    ";
    echo "TITLE: " . $item->book->title; . "
    ";
    echo "AUTHOR: " . $items->last_name .", ". $items->first_name;
    
    }
    
    produces:
    
    ISBN: 9780755342365
    TITLE: 101 Ways to Kill Your Boss
    AUTHOR: Roumieu, Graham

    The generated SQL:

    SHOW COLUMNS FROM books
    SHOW COLUMNS FROM authors
    SELECT * FROM (`books`)
    SELECT authors.* FROM (`authors`) 
    LEFT JOIN `authors_books` ON authors.id = author_id 
    LEFT JOIN `books` ON books.id = book_id 
    WHERE book.id = 1

    Which is correct, exactly what I want, except that my
    foreach loop stops there after 1, not continuing down
    the list for each book in my inventory.

    any suggestions or advice is appreciated!
    and again, thanks for all your work with this library.

  • #73 / Oct 02, 2008 6:39pm

    stensi

    109 posts

    Thanks guys 😊  I know how important documentation is as well, so am making a point to update it along with each new version, to reflect the changes made.

    @Isuka: Thanks for letting me know.  It looks like the same error will occur for strip_image_tags.

    @hugslife: The reason it’s only doing the one book, is because you’re only looping through the authors all list. You can’t loop through both the books all list and the authors all list in one foreach loop.  You’ll need a foreach loop for each all list you want to loop through.

    So, here’s how I’d loop through all your books, and then show all authors for each of those books:

    // Get all books
    $b = new Book();
    $b->get();
    
    // Loop through each book
    foreach ($b->all as $book)
    {
        echo 'ISBN: ' . $book->isbn . '
    ';
        echo 'Title: ' . $book->title . '
    ';
    
        echo 'Author(s): 
    ';
    
        // Get all authors for the current book
        $book->author->get();
    
        // Loop through each related author for the current book
        foreach ($book->author->all as $author)
        {
            echo $author->first_name . ' ' . $author->last_name . '
    ';
        }
    }

    UPDATE

    Version 1.3.3 has been released!

    View the Change Log to see what’s changed.

    In short, I fixed some validation rules (those that were overrides of incompatible CI Validation rules) and added in a couple of new validation rules (moved out of the Employee model example since I found them useful for many situations).

  • #74 / Oct 05, 2008 8:22am

    Matthew Pennell

    221 posts

    Ignore me, I’m an idiot.  :zip:

  • #75 / Oct 06, 2008 5:00am

    Boyz26

    28 posts

    Hi I am a little frustrated now so if anyone can help that would be great..

    Whenever I do this,

    function date2()
        {
            $person = new Person();
            $person->where('name','Andrew')->get();
    
            $person->book->get();
            
            foreach($person->book->all as $b):
                echo $b->author;
            endforeach;        
        }

    It simply returns all entries from Book. I have not saved any relationships yet, so by right it should not display anything.
    Can someone tell me what I did wrong here?

    Thank you.

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

ExpressionEngine News!

#eecms, #events, #releases