Welcome Guest, Not a member yet? Register   Sign In
DataMapper ORM v1.8.0

[eluser]WanWizard[/eluser]
Shouldn't it be '$this->post', and not posts?

And if you do this in a model method, try making a clone of $this first, and use that to fetch the first and last post entries.

If you're not sure, use check_last_query() to see what query your code has produced. Usually that will show you where you went wrong in the thought process.

p.s. you might want to look at the nestedsets extension. topics/posts are usually stored in a tree structure, which allows you to keep track of the sequence of replies.
Use a multi-root tree table where every tree is a topic with it's replies. The root can be the topic info. Use a small table with only index columns, and have it point (in a relation) to a messages table containing the actual message (with all its details). This also allows you to insert the same message at multiple points in the tree, which I use for example in forum announcements...

[eluser]Benedikt[/eluser]
I have a question.

I have a User Model and I have a Comment Model.

Now when I create the Comment I want it to be related to
a) The Creator (User Model)
b) The person it is related to (User Model)

In other words: A user creates a comment about a user.

I need to set up an advanced relationship but I dont know how I need to define it. I read the example about the creator and editor but how would this work for my example?

Thanks for help.

[eluser]Basketcasesoftware[/eluser]
Well, your comment only has one creator. That's a has_one relationship.
Your comment has only one person it applies to, that's another has_one relationship.

Comment
Code:
class Comment extends DataMapper {
    $has_one = array(
        'creator' => array(
            'class' => 'user',
            'other_field' => 'created_comment'
        ),
        'target' => array(
            'class' => 'user',
            'other_field' => 'target_comment'
        )
    );
}


User
Code:
class User extends DataMapper {
    $has_many = array(
        'created_comment' => array(
            'class' => 'comment',
            'other_field' => 'creator'
        ),
        'target_comment' => array(
            'class' => 'post',
            'other_field' => 'target'
        )
    );
}

See how they point to each other now?

[eluser]Benedikt[/eluser]
I will try that.

Thanks for your help. Now things are more clear!

[eluser]DonkeyKong[/eluser]
Hello, since I'm a newbie, what is the correct way of referencing Datamapper object in model:

Example 1:
Code:
class User extends DataMapper {
// relations and validations goes here

function activate_user($user_id, $activation_key)
{
    $user = new User();
    if ($user->where('email_key', $activation_key)->where('id', $user_id)->get())
    {
        $user->activated = 1;
        $user->save();
        return TRUE;
    }
    return FALSE;
}

}

Or..

Example 2:
Code:
class User extends DataMapper {
// relations and validations goes here

function activate_user($user_id, $activation_key)
{
    if ($this->where('email_key', $activation_key)->where('id', $user_id)->get())
    {
        $this->activated = 1;
        $this->save();
        return TRUE;
    }
    return FALSE;
}

}

Notice the "$this->.." and "$user = new User" difference.

[eluser]WanWizard[/eluser]
It depends on what you intend to accomplish.

Example2 uses the current object, which will be altered. Example1 doesn't alter the current object. Normally your model methods will interact with the data in the object, so Example 2.

[eluser]DonkeyKong[/eluser]
Ok, thanks, really appreciate it.

[eluser]Damir Sivic[/eluser]
Hi,first I'm sorry for my bad english.

I have problem with Nested Set Methods, to be more specific problem is when I move node to be a child of sibling node.
Code:
//table
id    konto     naziv     left_id     right_id
-----------------------------------------------
1     0         KONTA       1          10
13    100000    Konto       2          3
14    200000    Konto       4          9
19    200100    Konto i     5          6
20    200200    Konto izm   7          8


//$new_parent_id = 19
$parent = new Konta();
$parent->get_by_id($new_parent_id);

//$id = 20
$konto = new Konta();
$konto->get_by_id($id);
$konto->make_last_child_of($parent);

//generated SQL
UPDATE `kontas` SET `left_id` = kontas.left_id + 2 WHERE `kontas`.`left_id` >= '6'
UPDATE `kontas` SET `right_id` = kontas.right_id + 2 WHERE `kontas`.`right_id` >= '6'
UPDATE `kontas` SET `left_id` = kontas.left_id + -1, `right_id` = kontas.right_id + -1 WHERE `kontas`.`left_id` >= '7' AND `kontas`.`right_id` <= '8'
UPDATE `kontas` SET `left_id` = kontas.left_id + -2 WHERE `kontas`.`left_id` >= 9
UPDATE `kontas` SET `right_id` = kontas.right_id + -2 WHERE `kontas`.`right_id` >= 9

//table after
id     konto     naziv     left_id     right_id
----------------------------------------------------
1      0         KONTA        1            10
13    100000     Konto        2            3
14    200000     Konto        4            9
19    200100     Konto i      5            8<- only this changes
20    200200     Konto izm    7            8
https://bitbucket.org/wanwizard/datamapp...bling-node

[eluser]WanWizard[/eluser]
Possible, it's still expirimental code.

I've got a feeling the '+ -' things have something to with it. I'll try to find some time to have a look at it. In the meantime, please create an issue on http://bitbucket.org/wanwizard/datamapper/issues, and include a link to your post in the project ticket.

[eluser]Colm Ward[/eluser]
Hi

Just a quick clarification question on the production_cache method.

I've tried using it after adding a new column to a database table. I add the new table column via a direct SQL command to the database, and then I call a clear_cache controller method via the browser which creates a new model and calls $model->production_cache()

The cache file for the model is regenerated, but it does not reference the new table column. Is this what is supposed to happen?

cheers,
Colm




Theme © iAndrew 2016 - Forum software by © MyBB