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]
  • #841 / Feb 20, 2011 3:56am

    Basketcasesoftware

    442 posts

    What’s the way you are doing it WITH the ORM?

  • #842 / Feb 20, 2011 12:04pm

    ramm

    53 posts

    That’s the way WITH ORM. I was wondering if there’s a better way to do it.

    This is just a test, i’m not actually echoing the results in the controller…

  • #843 / Feb 20, 2011 2:51pm

    Basketcasesoftware

    442 posts

    Ok. The context implied the code that followed was without ORM. Can you show how you would do it without it then?

    In fact, what exactly are you trying to do with the code? And DataMapper is up to version 1.8 now. If you are still using DMZ 1.7.1 (which is implied by you posting in this thread), there might be features available that might make things easier anyways.

  • #844 / Feb 20, 2011 6:33pm

    ramm

    53 posts

    Oh, i’m sorry i didn’t know it was only for 1.7.1, thought it was growing together…

    Anyway, this is the way i do it without ORM, using only CI libraries:

    function test()
        {
            $this->load->model(array('chains_model', 'restaurants_model'));
            $chains = $this->chains_model->get_chains();
            foreach($chains as $c)
            {
                echo "<h3>".$c->name.</h3><p>;<br />
                $restaurants = $this->restaurants_model->get_restaurants(array('chain' => $c->id));<br />
                foreach($restaurants as $r)<br />
                {<br />
                    echo $r->name."<br />
    ";<br />
                }<br />
            }<br />
        }

    I need something like this:

    Chain: McDonalds
    -Mc Donalds Rest I35 North
    -Mc Donalds Austin HWY
    -Mc Donalds O’Connor Road

    Chain: Subway
    -Subway Forum
    -Subway Nacogdoches
    -Subway Northstar Mall

    Chain: Red Lobster
    -Red Lobster I35 North

    And so on…

  • #845 / Feb 20, 2011 6:50pm

    Basketcasesoftware

    442 posts

    No, not only. But with the thread title it helps to make sure. There have been cases where people have gotten confused.

    And how is the weather right now in San Antonio? 😊

    It kind of sucks both of your code posting are on different pages. Makes it kind of tough to compare the two.

  • #846 / Feb 20, 2011 7:09pm

    Basketcasesoftware

    442 posts

    Won’t this work? You haven’t given the structure of your tables so I’m having to guess on the code.

    function test()
        {
            $c = new Chain();
            $c->get();
            
            foreach($c as $chain)
            {
                echo "<h3>".$chain->nme."</h3><p>";<br />
                foreach($chain->rest as $rest)<br />
                {<br />
                    echo $rest->name."<br />
    ";<br />
                }<br />
            }<br />
        }

  • #847 / Feb 20, 2011 7:50pm

    WanWizard

    4475 posts

    I understand the issue, as it runs 1 query to get the chains, and then 1 query for every chain found to get the restaurants of that chain.

    There are now two discussions going on about the same subject. May I suggest we continue there to keep the discussion in one place? I also gave a suggestion for solution there…

  • #848 / Feb 20, 2011 8:01pm

    Basketcasesoftware

    442 posts

    Where’s the other discussion? the DataMapper 1.8 thread? I was just responding to the posts.

  • #849 / Feb 20, 2011 8:59pm

    Basketcasesoftware

    442 posts

    I found it.

  • #850 / Mar 13, 2011 6:09am

    simple question but I am exhausted in finding answer if some one can get me started

    I have two tables

    ————- users———————||
    |——————————————-||
    |id | field1 | field2 | field3||
    |——————————————-||


    |———————-xshouts_members———
    |——————————————————-|
    |id | UID | fieldA | field B | field C|
    |——————————————————-|


    Relation is one to one each xshouts_members=>UID represents users=>id
    I want

    $m = new Member();
    $m->get();
    echo $m->juser->get()->field2;

    yes i want to use juser for users table from xshouts_members point of view (renamed sort of)

    and yes may be some day i will need $u->member (from users to member)

    thanks for your effort ..

  • #851 / Mar 13, 2011 7:35am

    WanWizard

    4475 posts

    Just name your model ‘juser’, and in that model set $this->table to ‘users’ make override the models table name.

  • #852 / Mar 13, 2011 8:08am

    Just name your model ‘juser’, and in that model set $this->table to ‘users’ make override the models table name.

    its not that simple.. you have not noticed the relative field is UID not UID_id ... some how i have managed it to work now second problem .. and this can be helpful to other also

    I have a table members, and the members can have another members as friends
    its in another table stored as

    id | members_id | friends_members_id |approved status

    all good from one point “get all friends of member 87”
    but the point is in this social application a member can be at members_id as he added a friend or he can be at friends_members_id as his friend added him. now how to get all friends of a member and even only those who are approved !!!

  • #853 / Mar 13, 2011 8:33am

    WanWizard

    4475 posts

    If you don’t follow Datamapper’s design guidelines, you’re making it very difficult for yourself, and for us trying to support you.

    Self relationships in a many-to-many relation are described in the manual.

    class Member extends DataMapper {
        $has_many = array(
            'friend' => array(
                'class' => 'member',
                'other_field' => 'member'
            ),
            'member' => array(
                'other_field' => 'friend'
            )
        );
    }

    This will require a relationship table called ‘members_members’, in which you will have the columns ‘id’, ‘member_id’, ‘friend_id’, and ‘approved_status’.

    You can then get the list of John’s approved friends by using

    $member = new Member();
    $member->get_by_name('John');
    $member->friend->where_join_field($member->friend, 'approved_status', '1')->get();
  • #854 / Mar 13, 2011 9:14am

    heads off to you…

    agreed i have to use guideline .. i am almost near what you said but major question

    As per your said I can get all friends of John if he has its id in member_id and friends id in friend_id, what if any of his friend added him in his list then also he is Johns friend. can there be a simple workaround in Datamapper


    since I am provided with database by my client this relation ship is in “jos_xshouts_members_has_friends” table with fields
    id | member_id | friend_member_id
    as per guideline I have gone to this ...

    class Member extends DataMapper{
        var $table='users';
        var $has_many=array(
            'member'=>array(
                'other_field'=>'friend_member',
                'reciprocal' => TRUE,
                'join_table'=>'jos_xshouts_members_has_friends'
            ),
            'friend_member'=>array(
                'class'=>'member',
                'other_field'=>'member',
                'join_table'=>'jos_xshouts_members_has_friends'
            )
        );

    but $m=new Member();
    $m->friend_member->get() gives nothing, I have also tried $m->member->get() .. but same ..

    Thanks for your time

  • #855 / Mar 13, 2011 9:50am

    WanWizard

    4475 posts

    Use check_last_query() to see the query produced, and try to deduct from there what is wrong.

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

ExpressionEngine News!

#eecms, #events, #releases