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 ORM v1.8.2

November 30, 2011 3:43pm

Subscribe [100]
  • #211 / Mar 16, 2012 6:58am

    Maglok

    402 posts

    @Maglok,

    Datamapper is about relations, it can’t produce data in a relation that is not related. 😉

    The best option is probably to retrieve all hobbies, and retrieve the person including it’s related hobbies. Then iterate over the hobbies, and check if the id exists as a key in persons->hobbies->all. If so, that hobby is related, and if not, well…

    That is a good guideline, DM being about relations. Anyway that is how I fixed it indeed. Thanks!

  • #212 / Mar 16, 2012 8:07am

    WanWizard

    4475 posts

    @Ikkes,

    Please download the latest one (https://bitbucket.org/wanwizard/datamapper/get/tip.zip) and install it, so we’re looking at the same code.

    Just tried it here with the latest code from bitbucket, which loads the set database name without problems (and generates an “invalid database group” error when I use an undefined name).

  • #213 / Mar 16, 2012 9:37am

    North2Alaska

    58 posts

    @WanWizard I’ve simplified the model down to nothing.

    class User extends DataMapper {

    var $prefix = 'auth_';

    public function post_model_init() {
    var_dump(get_object_vars($this));

    }
    }

    and the controller

    class Users extends CI_Controller {

    function index() {

    $u = new User();
    $u->where('username', 'North2Alaska')->get();

    echo 'Email: ' . $u->email . '
    ';
    }
    }

    Still no change.

  • #214 / Mar 16, 2012 9:55am

    North2Alaska

    58 posts

    @WanWizard

    I can set the table name like

    var $table = ‘auth_users’;

    and that works.

    When I finally got that to work I also got the var_dump output.  The prefix was empty.

  • #215 / Mar 16, 2012 10:03am

    North2Alaska

    58 posts

    @WanWizard

    Another interesting tidbit, the model template model has no mention of prefix in it.  It probably doesn’t really mean anything as it’s only a example, but it is pretty detailed in what can be in the model.

  • #216 / Mar 16, 2012 11:24am

    WanWizard

    4475 posts

    I can not reproduce it here, if I set a prefix in an existing model it immediately complains it can’t find the table, and gives the table name with the prefix.

    Which leads me to believe that you’re not using the latest version of the code.

    So the same advice as to @Ikkes: Please download the latest version (https://bitbucket.org/wanwizard/datamapper/get/tip.zip) and upgrade your installation.

  • #217 / Mar 16, 2012 12:16pm

    North2Alaska

    58 posts

    @WanWizard

    I’ll do that and let you know.

    BTW:  I was out looking at the 2.0 version but nothing has change for a few months.  Is progress still being made?  I’m going to be doing a lot of DM and would like to contribute in some way.

  • #218 / Mar 16, 2012 2:56pm

    tarciozemel

    82 posts

    @tarciozemel,

    Datamapper passes where() clauses unaltered to $this->db->where(). Maybe something changed in CI’s DB drivers?

    You can try

    ...
    $companies->where('MATCH (foo) AGAINST ("bar" IN BOOLEAN MODE)', NULL, FALSE);
    ...

    which will disable escaping…

    Your tip did the job! Thank you!

    PS: Sorry for my delayed response, but some times the forum system not send me the message alert email…

  • #219 / Mar 16, 2012 3:07pm

    WanWizard

    4475 posts

    BTW:  I was out looking at the 2.0 version but nothing has change for a few months.  Is progress still being made?  I’m going to be doing a lot of DM and would like to contribute in some way.

    I started it because I wanted to do a full rewrite to deal with the 2.0+ changes in CI, and the fact that the DM code is getting dated (and got a bit bloated over the years).

    But currently it works, and I don’t have time for it. Bread on the table and my work for Fuel goes first at the moment.

  • #220 / Mar 17, 2012 6:56am

    Ikkes

    3 posts

    @WanWizard

    I have downloaded the latest DataMapper as you told me. The script is working very fine now 😊

    Thank for your help.

    With kind regards,
    Dennis

  • #221 / Mar 17, 2012 7:33am

    North2Alaska

    58 posts

    @WanWizard

    I think @Ikkes and I are in parallel universes or something…  😊

    I have installed the most recent version and all is working well. 

    Thanks for all the help!

  • #222 / Mar 17, 2012 11:57am

    WanWizard

    4475 posts

    Cool. These are the best problems to fix… 😊

  • #223 / Mar 17, 2012 4:42pm

    North2Alaska

    58 posts

    As I begin to learn DM, I have a question about overriding the table name with either the $prefix or $table variables.  Is there any disadvantage to doing the override?  Why not just create the model and specify the table

    Class User extends DataMapper {
    $table = 'MyUserTableForAuthorization';

    }

    Will something like this have any overall negative impact?  Or is it just one more thing to have to remember?

  • #224 / Mar 17, 2012 5:11pm

    North2Alaska

    58 posts

    And another one.

    I love the auto entered create and update datetimes.  I want to extend the functionality to include the id of the current user.  I’ve been looking at the save function, but I don’t see a good way to implement it.  Ideas?

  • #225 / Mar 17, 2012 6:25pm

    North2Alaska

    58 posts

    As I begin to learn DM, I have a question about overriding the table name with either the $prefix or $table variables.  Is there any disadvantage to doing the override?  Why not just create the model and specify the table

    Class User extends DataMapper {
    $table = 'MyUserTableForAuthorization';

    }

    Will something like this have any overall negative impact?  Or is it just one more thing to have to remember?

    Well, I see the first challenge.  When using a relationship, the many to many table takes on the table name so, if I have two tables, auth_user and auth group and they are joined by another table, I named it auth_group_user, DM looks for a table’auth_role_auth_user’.  It’s not the preferred, but I can live with it.

    But if I set the $prefix instead of $table, then I get more what I expected, auth_roles_users.  This is better and I think I will go with this one.

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

ExpressionEngine News!

#eecms, #events, #releases