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]
  • #451 / Jan 29, 2009 7:57am

    Iverson

    153 posts

    unset($this->{$object->model});

    with this one:

    $this->{$object->model}->clear();

    This should fix the problem, while still clearing out the related object.

    UPDATE Question:
    What version of PHP are you running?  I tested it on mine, and PHP 5.2.6 had no problem calling the __get method after an unset.

    UPDATE 2
    One more: you actually have a mistake in your example code!  You are calling sch->school, but you mean sch->student.  That’s your error.

    I actually don’t have that line in my datamapper file (1.6.0). And this isn’t my actual situation. I just quoted it instead of saying the same thing over. My code is actually:

    $cl = new Client();
    $cl->get_by_id(1);
    $cl->payment->get(); // Throws the error

    And I’m running 5.2.8. Maybe that’s a problem?

  • #452 / Jan 29, 2009 8:16am

    OverZealous

    1030 posts

    Hmm, I must have modified MY version of DM already!  Ha.  OK, the correct line is to replace

    // line # 2416
    $this->{$object->model} = NULL;

    with

    unset($this->{$object->model});

    Which will fix your problem.

    I apologize, my DM has a handful of bugfixes that I’m pretty sure I sent to Stensi, but have long since forgotten about…

    Then your problem should be gone.

  • #453 / Jan 29, 2009 8:39am

    Iverson

    153 posts

    Thanks for the help, but that didn’t work either. I think it’s because #2416 is in a delete relationship function. All I’m trying to do is get the related table.

    // Client Model
    class Client extends DataMapper {
    
        var $has_many = array('payment' => 'payments');
        var $unix_timestamp = TRUE;
        /**
         * Constructor
         *
         * Initialize DataMapper.
         */
        function Client()
        {
            parent::DataMapper();
        }
    
    
    // Payment Model
    class Payment extends DataMapper {
    
        var $has_one = array('client' => 'clients');
        var $unix_timestamp = TRUE;
    
        /**
         * Constructor
         *
         * Initialize DataMapper.
         */
        function Payment()
        {
            parent::DataMapper();
        }
    
    // Controller
    $cl = new Client();
    $cl->get_by_id(1);
    $cl->payment->get();
  • #454 / Jan 29, 2009 3:35pm

    OverZealous

    1030 posts

    Hmm, you need to be more specific when you post questions.  The problem you referenced before was specifically related to deleting a related item, and is completely unrelated to the code you are showing.

    In your quoted text, you are using the old method.  DataMapper 1.6.0 (actually, since 1.4.0) doesn’t use the associative has_one and has_many arrays.  You just need to list the model names of the related objects.

    Please read the DM change log.  $unix_timestamp can also be specified within the DataMapper config file, and is not needed on the individual models unless you want different types of timestamps per model.

  • #455 / Jan 29, 2009 5:36pm

    tdktank59

    322 posts

    Is there a way to get thing out of the relation table?

    For example: I need to get start_date and end_date from the roles_users table

    users
    id
    username
    email
    password
    etc…

    join_roles_users
    id
    role_id
    user_id
    created_on
    updated_on
    start_date
    end_date

    roles
    id
    name
    description
    created_on

    UPDATE:
    For the moment im just using custom queries attached to the page and method models. If there is a way to do it with Datamapper sweet otherwise this is a work around for it at the moment…

  • #456 / Jan 30, 2009 8:03am

    macigniter

    244 posts

    i just found out about this beautifully documented class and am just now experimenting with it. i have one question and please excuse me if it is stupid:

    i ususally use prefixes for a logical group of tables (e.g. user management = user_****, tracking = track_**** etc.)

    so i have a “faqs” table as well as a “track_faqs” table which holds all the stats. technically i would join the tables like this:

    faqs
    id
    question
    answer
    ...

    track_faqs
    id
    hash
    created

    join_faqs_track_faqs
    id
    faq_id
    track_faq_id

    is it possible to use an underscore in a table name or is it forbidden?

  • #457 / Jan 30, 2009 8:19am

    Murodese

    53 posts

    Not a problem as far as I’ve encountered.

  • #458 / Jan 30, 2009 8:39am

    macigniter

    244 posts

    another question…

    i have a “files” table that stores information on uploaded files. this table should have relations to
    1. the user id of the user that uploaded the file (1:1)
    2. a list of users that are allowed to view the file (m:n)

    how would i do this without having to use the same join table name twice?

    files
    id
    label
    descr
    ...
    created
    updated

    join_files_users (to store the user id of the creator of a file)
    id
    file_id
    user_id

    join_files_users (to store the users that are allowed to download a file)
    id
    file_id
    user_id

    i don’t know how to solve this since i would have to use the same table name for the join tables, right?

  • #459 / Jan 30, 2009 8:46am

    Murodese

    53 posts

    class Uploader extends DataMapper
    {
      var $table = 'users';
    
      var $has_one = array('file');
      
      // ...
    }
    
    class User extends DataMapper
    {
      var $table = 'users';
    
      var $has_many = array('file');
    
      // ...
    }
    
    class File extends DataMapper
    {
      var $table = 'files';
    
      var $has_many = array('user');
      var $has_one = array('uploader');
    
      // ...
    }

    And join tables would become files_users and files_uploaders.

  • #460 / Jan 30, 2009 9:12am

    macigniter

    244 posts

    Thanks!! I really appreciate your quick help

  • #461 / Jan 30, 2009 12:13pm

    wolffc

    14 posts

    I noticed that datamapper does a SELECT * from table LIMIT 1 when i create an object.  I am guessing it does this to find the columns.  Can I just predefine my columns in the model so i don’t have to do that query or an option to turn it on or off?

  • #462 / Jan 30, 2009 1:08pm

    OverZealous

    1030 posts

    I bet you would find, if you compared it, that that query takes so little time that it doesn’t make much difference — it takes about 2ms on one of my testing server’s tables.  (Unless your DB is in a different datacenter…)

    It’s actually CodeIgniter doing it, using the driver.  Also, DM has been optimized to only call this once (the first time a specific type of model is created).  If yours is making more than one query per model, make sure you are using the latest version of DM (1.6.0 as of this posting).

    To disable it you’d have to edit DataMapper itself, as it is central to the constructor.

  • #463 / Jan 31, 2009 3:42am

    Murodese

    53 posts

    I bet you would find, if you compared it, that that query takes so little time that it doesn’t make much difference — it takes about 2ms on one of my testing server’s tables.  (Unless your DB is in a different datacenter…)

    It’s actually CodeIgniter doing it, using the driver.  Also, DM has been optimized to only call this once (the first time a specific type of model is created).  If yours is making more than one query per model, make sure you are using the latest version of DM (1.6.0 as of this posting).

    To disable it you’d have to edit DataMapper itself, as it is central to the constructor.

    Yeah, 0.2ms for that query on our production server 😊

    It’s not really an issue.

  • #464 / Feb 02, 2009 1:48pm

    bEz

    110 posts

    I’m not able to key in the appropriate search term, so I’m posting my question meanwhile I continue my search attempts.

    I’m relatively still new to the CI framework, however, I’ve decided to develop with DM (despite the restraints of join tables).

    I understand that there is a method of utilizing multiple databases in the CI core, however,
    what is the method (if possible) of using multiple databases with Datamapper?

  • #465 / Feb 02, 2009 1:59pm

    Daniel H

    197 posts

    How would I create a relationship whereby one object can relate to two separate instances of another object. For example, for I want to link - say - a ‘post’ object to two ‘user’ objects: one that has created the post, and another that last edited the post.

    Or perhaps a ‘task’ could be ‘owned’ by a user, but also ‘assigned’ to another user?

    Any ideas?

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

ExpressionEngine News!

#eecms, #events, #releases