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]
  • #196 / Apr 28, 2010 10:38am

    OverZealous

    1030 posts

    @ianbborg

    The table name being generated is a join table.  At least, I have to assume that, because you didn’t include the code that generates this query.

    You probably are intending to use ITFKs, but you have them mis-named.  If DMZ doesn’t see the ITFK name on the table, it assumes there is a dedicated join table.  The reason the table name appears twice is DMZ always adds an alias to the table name, to allow for advanced and deep queries.

    Your problems are most likely stemming from the fact that your model names and table names are very different.  While it is possible to do this with DMZ, the ability to use a different $table name than the generated one is specifically for helping with unusual pluralizations, not for complete renames.  The way you are using it is not supported, so I can’t help you figure out your problem further.

    (Just like how “modules” aren’t supported.)

  • #197 / Apr 28, 2010 10:45am

    ianbborg

    3 posts

    First of all thanks for your response, secondly I resolved the problem by doing advanced relationships using the “class” and “other field” fields. For the models that don’t use the same name as in the db I named the key of the relationship as the database name:

    class TownsCountry extends DataMapper
    {
        public $table ="general_towns_country";    
        
        /** 
         * Relationships 
         * @var Array
         */    
        public $has_one = array('town',
                                'general_country'=>array('class'=>'country',
                                                         'other_field'=>'g_cid'),
                                'general_county'=>array('class'=>'county',
                                                         'other_field'=>'g_countyid'));
    
        public function __construct()
        {
            // model constructor
            parent::__construct();    
             
        }
        
    }


    The only problem remaining is when I try to save a TownsCountry object and I pass a Town & Country object as parameters, it doesn’t seem to generate the SQL for the Country object so I save it by giving it the values instead.

  • #198 / Apr 28, 2010 10:48am

    OverZealous

    1030 posts

    @ianbborg

    I’m glad you got it resolved, I just want to be clear that this is not how DMZ is designed.  If you design your database and models according to the rules in the manual, just about everything you did is automatically handled.  😊

  • #199 / Apr 28, 2010 6:41pm

    Mareshal

    230 posts

    I want to change the default folder for loading models. Is there any setting for this?

    I modified the code: libraries/datamapper.php:811

    $file = $path . “datamapper/” . $class . EXT;

  • #200 / Apr 28, 2010 6:46pm

    OverZealous

    1030 posts

    There is no setting.  DMZ uses the standard CodeIgniter models directory.

    There was some code provided by Jack Scott that should help with CI 2.0 and EE, because those apparently allow for multiple model directories.

    However, all you have to do is register your own spl_autoload function.  You don’t need to modify DMZ at all.  You can register this in a globally-loaded helper, library, or even a DMZ extension.

  • #201 / Apr 28, 2010 6:52pm

    Mareshal

    230 posts

    A better approach at this moment.

    I already had my own config file: my_config.php

    A new line there:
    $config[‘dmz_models’] = “datamapper/”;

    and

    $file = $path . $CI->config->item(‘dmz_models’) . $class . EXT; // 😛 and is done

    You should make a setting for this in datamapper config file. Is a suggestion. I don’t have time to digg in the code to add this to DMZ’s config file.

  • #202 / Apr 28, 2010 7:04pm

    OverZealous

    1030 posts

    I respectfully disagree.  There is already a perfectly good models directory included with CodeIgniter.  I have yet to get a good argument for why you would want your models in a different location.

    DMZ also already searches the models directory recursively, so you can put your DMZ models in a subfolder of application/models, if you wish, no modification necessary.

  • #203 / Apr 28, 2010 7:07pm

    Mareshal

    230 posts

    I respectfully apologize then. I didn’t know that DMZ searches in subfolders. Thank you. I just wanted to keep my DMZmodels separated from the rest of the CImodels.

  • #204 / Apr 28, 2010 7:09pm

    OverZealous

    1030 posts

    I should have written:

    I respectfully disagree 😛

    😉

  • #205 / May 02, 2010 3:39am

    Greetings,

    I am following the included example (somewhat) for a simple login procedure, but I’m running into a problem; namely, the login page itself only takes the username and password as parameters, but when a $this->validate()->get() call is run, it returns a MySQL syntax error.  The query shown is along these lines:

    SELECT * FROM (`users`) WHERE `name` = ‘Vinzent Zeppelin’ AND `password` = ‘67174866a…etc’ AND `other_field1` = AND `other_field2` =

    The relationship between `user` and `other_field1` and `other_field2` is a bit unusual in that both fields are foreign keys pointing to a single column in another table; in other words, it’s a “has two” relationship.  The “other_field1” and “other_field2” are flagged as “required” in the validation rules (they are required when saving a user), and they also are foreign key attributes listed in the $has_one array of the user model (following the model in “Advanced Relationships” of the user guide).  The problem is, it seems that DMZ automatically “validates” these relationships and includes them in the WHERE clause of the query even if they’re empty, generating a broken query.  Removing other_field1 and other_field2 from the $has_one array seemed to resolve the error; removing their “required” flags in the $validation array did not.  Is there a workaround of some sort, or have I overlooked something?

  • #206 / May 02, 2010 10:49am

    Mareshal

    230 posts

    I have this structure

    Users: user_id, user_name, user_email, user_site
    Article: article_id, article_title, article_link, user_id(FK.user_id -> Users)

    Can I produce this query with DMZ?

    SELECT a.*, u.user_name, u.user_email, u.user_site
    FROM article AS a
    LEFT JOIN users AS u
    ON a.user_id = u.user_id
    WHERE a.article_id = '{$art_id}'
  • #207 / May 04, 2010 6:47am

    Lord_Jago

    7 posts

    I have this structure

    Users: user_id, user_name, user_email, user_site
    Article: article_id, article_title, article_link, user_id(FK.user_id -> Users)

    Can I produce this query with DMZ?

    SELECT a.*, u.user_name, u.user_email, u.user_site
    FROM article AS a
    LEFT JOIN users AS u
    ON a.user_id = u.user_id
    WHERE a.article_id = '{$art_id}'

    It’s possible with the include_related function. Something like :

    $article = new Article();
    $article->where('id', $art_id);
    $article->include_related('user', array('username', 'email', 'site'));
    $article->get();
  • #208 / May 04, 2010 6:54am

    Lord_Jago

    7 posts

    Hi,

    I have a table USER which is self related (a many to many relationship). So I have the following structure :
    USER : id, username…
    SELFUSER : id, userA_id, userB_id

    I’m looking for a way to do one of these 2 queries :

    SELECT u.*
    FROM users u
    LEFT JOIN selfuser su
        ON u.id = su.userA_id
        AND su.userB_id = $user_id

    Or,

    SELECT u.*
    FROM users u
    LEFT JOIN selfuser su
        ON u.id = su.userA_id
    WHERE su.userB_id = $user_id

    Impossible for me to find an easy way to do it. The only solution I’ve found is to use subqueries, which is quite complicated and dirty for such a simple query.


    Thanks,
    Julien

  • #209 / May 04, 2010 12:34pm

    Wazzu

    27 posts

    Advanced Relationship

    Hi all. I’m not able to understand how advanced relationships work.
    I’ve read user guide and made tests, but I can’t understand how field names are used.

    This is my sample case:
    - table users(id, name)
    - table quotes(id, client_id, worker_id)
    - user model and quote model

    One user (worker_id) can create a new quote for other user (client_id).
    ‘worker_id’ and ‘client_id’ are in fact ids from users table.

    How should I make relationships? This is what I’ve done:

    class Quote extends DataMapper {
      var $has_many = array(
            'client_id' => array('class' => 'user','other_field' => 'client'),
            'worker_id' => array('class' => 'user','other_field' => 'worker')
      );
    }
    class User extends DataMapper {
      var $has_one = array(
        'client' => array('class' => 'quote', 'other_field' => 'client_id'),
        'worker' => array('class' => 'quote', 'other_field' => 'worker_id')
      );
    }

    Is that right? And from my controller, how should I populate this? I want to get something like this:

    <?php
    $q = new Quote($id);
    
    $q->client->get();
    echo $q->client->name;
    
    $q->worker->get();
    echo $q->worker->name;
    ?>

    Please, help me understanding this relationships.
    Thanks all

  • #210 / May 04, 2010 11:17pm

    NachoF

    171 posts

    I just ran into a little trouble

    I need to use the sql query syntax like so.

    $o=new Object();
    $where="id=2";
    $o->where($where)->get();

    I get Database error

    ERROR:  column “id=2” does not exist
    LINE 3: WHERE “id=2”

    SELECT *
    FROM “entities”
    WHERE “id=2”

    Am I missing something obvious?

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

ExpressionEngine News!

#eecms, #events, #releases