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

[eluser]WanWizard[/eluser]
Two options:

either the bootloader wasn't initialized properly as it looks like the standard CI driver is loaded, or the spark is out of date.

And I assume the last, appearantly they don't like version numbers with 4 digits. Datamapper moved to 1.8.2.1 quite some time, and although I've updated the spark several times, it keeps serving the 1.8.2 version, which doesn't work on the latest CI versions.

I suggest either to install the latest version manually (like you would do without the spark), or overwrite the files of the installed spark with the files downloaded.

I will make another attempt at updating the spark...

[eluser]shenanigans01[/eluser]
I've checked the spark it doesn't appear to be out of date. Although it says version 1.8.2 (on the spark file & folder name) if I open libaries/datamapper.php it is marked @version 1.8.2.1

again everything works perfectly if I leave the index.php in it's original position, it loads and I can use it correctly; it only fails when I index.php into the webroot by itself.

[eluser]WanWizard[/eluser]
Where exactly do you get this error?

Anything other library you use? Problem here is $this->db points to the original CI class, and not to DM's stub class.

Otherwise, could you check in the bootloader if
Code:
if (file_exists($file = DATAMAPPERPATH.'third_party/datamapper/system/'.$class.'.php'))
actually finds the DM stub classes? Because if this isn't loaded, it will not work.

[eluser]shenanigans01[/eluser]
I've started with a new installation of CI.(2.1.2). Installed the latest DM Spark (library version 1.8.2.1), as mentioned i've moved the index.php to it's own folder, edited the system & app path within it.

application
system
sparks
htdocs->index.php

In my welcome controller I use
Code:
$user = new User();
with nothing else and it returns the error. if I remove that line the welcome view loads correctly. If I put index.php back where it originally comes it works fine so it has to be a path error somewhere I'm just trying to figure out where... Have you tried moving the index.php file with a spark? and if so does it break DM for you?

[eluser]WanWizard[/eluser]
I don't have a CI install with sparks here atm, that's why I asked you to check if the bootloader is really loaded, and if it can find DM's system class extensions.

[eluser]shenanigans01[/eluser]
sorry exactly where would you like me to place that code? I'll add it now

[eluser]WanWizard[/eluser]
That code is in the DM bootstrap, and I have a feeling it fails, so it doesn't load the DM stub classes.

[eluser]coldKingdom[/eluser]
Hi, and thank you for a wonderful library!

I have a table like this

friends_users
id - unique ID
user_id - relates to usertable
friend_id - relates to usertable
relationship_id - relates to relationship status table
approved

It's the relationship_id I have little bit of a problem with as it should relate to a table like

relationships
id - unique ID
title - What type of relationship. Friend etc.

So in my code I have

User-model

Code:
<?php

class User extends DataMapper {
    
    var $has_many = array(
        "news",
        "image",
        "friend" => array(
            'class' => 'user',
            'other_field' => 'user',
            ),
        'user' => array(
            'other_field' => 'friend'
            )
        );

User-controller
Code:
//Create user objects
        $users = new User();
        $users->select("id, first_name, last_name, presentation, picture");
        $users->where("id", $id);

        //Get the user
        $users->get(1);
        
        //If the ID does not exist
        if (!$users->exists())
            show_404();
        
        //Get the users friends
        $users->friend->select('id, first_name, last_name');
        $users->friend->where('approved', '1');
        $users->friend->get();

I probably should do a $users->friend->where_join_field/include_related or something like that, but it only relates to the user and it's driving me nuts as it should get the title of the relationship Smile

Can anyone put me in the right direction? All help is highly appreciated.

Thank you!

[eluser]WanWizard[/eluser]
Datamapper doesn't support three-way relationships, so you can't do this.

You can work around that my making a model for the relationship table, and convert the many-to-many between users and friends to one-to-many's with this new model. You can then make a one-to-many between the new model and relationships.

You can then run your queries from the perspective of this new model. To make it easier you could add some helper methods to this new model, for example:
Code:
public function all_friends_of_user($userid)
{
    // get the friends of this user as friend model objects
    $this->where('user_id', $userid)->include_related('friend', NULL, TRUE, TRUE)->get();

    // $this->friend now contains all related friends
    return $this;
}

[eluser]coldKingdom[/eluser]
[quote author="WanWizard" date="1342256608"]Datamapper doesn't support three-way relationships, so you can't do this.

You can work around that my making a model for the relationship table, and convert the many-to-many between users and friends to one-to-many's with this new model. You can then make a one-to-many between the new model and relationships.

You can then run your queries from the perspective of this new model. To make it easier you could add some helper methods to this new model, for example:
Code:
public function all_friends_of_user($userid)
{
    // get the friends of this user as friend model objects
    $this->where('user_id', $userid)->include_related('friend', NULL, TRUE, TRUE)->get();

    // $this->friend now contains all related friends
    return $this;
}
[/quote]

Thank you for a quick answer!

I ended up with the code
Code:
$friends = new Friend();
$friends->select('friend_id');
$friends->where('user_id', $id);
$friends->where('approved', '1');
$friends->include_related('user', array('first_name', 'last_name'));
$friends->include_related('relationship', array('title'));
$friends->get();




Theme © iAndrew 2016 - Forum software by © MyBB