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

[eluser]WanWizard[/eluser]
Looks like you have defined the relation 'group' as required. Giving 'group_id' a value doesn't make the related 'group' object magically appear.

[eluser]Maglok[/eluser]
I just wanted to confirm something about join fields.

The include_join_fields() examples in the user guide say this:
Code:
// Create User
$u = new User();
$u->get_by_id($userid);

// get all alarms for this user, and include the extra 'wasfired' field
$u->alarm->include_join_fields()->get();

foreach($u->alarm as $alarm) {
    if($alarm->join_wasfired) {
        echo("{$alarm->name} was fired\n");
    } else {
        echo("{$alarm->name} was NOT fired\n");
    }
}

What if I have a collection of users that I need to get the include_join_fields() for?

This works, but seems like dirty coding to me:
Code:
// Get Users
$u = new User();
$u->get();

// get all alarms for this user, and include the extra 'wasfired' field
foreach($u as $user) {
    $user->alarm->include_join_fields()->get();

    foreach($user->alarm as $alarm) {
        if($alarm->join_wasfired) {
            echo("{$alarm->name} was fired\n");
        } else {
            echo("{$alarm->name} was NOT fired\n");
        }
    }
}

What is the best practice here?

[eluser]jordanarseno[/eluser]
Update -- Ignore This
I found my answer here: http://stackoverflow.com/questions/54485...datamapper

Hey WanWizard/folks.

I understand that Datamapper ORM supports both MySQL and Postgres backends. The application I'm building requires both.
What's your suggestion for getting it running on both databases at once?

There are a few ways I can see this working -- forgive me if I've just missed the documentation:

1) I could put a field on the model ... var $db = "postgres"; or var $db = "mysql"; for instance.
2) Separate the postgres models into a new models folder ... /application/pgmodels for instance.
3) Prefix the postgres models with Pg... Pganimal() for instance.

What's your suggestion here?

As always, your help is appreciated.

[eluser]kakallatt[/eluser]
Hi WanWizard,

I have 2 classes:

Code:
class User extends DataMapper {
        // Table: users


// Relationship
var $has_one = array('group');
var $has_many = array('privilege', 'page', 'article');
}

class Page extends DataMapper {
        // Table: pages

// Relationship
var $has_one = array('user');
}

When I delete a user I got a database error:
Code:
Table 'cms.pages_users' doesn't exist

DELETE FROM `pages_users` WHERE `user_id` = 22

[eluser]Damir Sivic[/eluser]
"A joining table must exist between each $has_many related normal tables." DM manual

"Joining tables must be named with both of the table names it is joining, in alphabetical order, separated by an underscore (_). For example, the joining table for users and countries is countries_users." DM manual

[eluser]kakallatt[/eluser]
[quote author="Damir Sivic" date="1367846376"]"A joining table must exist between each $has_many related normal tables." DM manual

"Joining tables must be named with both of the table names it is joining, in alphabetical order, separated by an underscore (_). For example, the joining table for users and countries is countries_users." DM manual[/quote]

I think: One to many or many to one don't need a joinning table. In pages table, I have a field named: user_id.

[eluser]Damir Sivic[/eluser]
Quote:
Code:
Table 'cms.pages_users' doesn't exist

DELETE FROM `pages_users` WHERE `user_id` = 22

but the error says that you using many to many relationship.

[eluser]kakallatt[/eluser]
[quote author="Damir Sivic" date="1367918837"]
Quote:
Code:
Table 'cms.pages_users' doesn't exist

DELETE FROM `pages_users` WHERE `user_id` = 22

but the error says that you using many to many relationship.[/quote]

It is so weird. I don't understand, in user class I defined:
Code:
var $has_many = array('page');

and page class:
Code:
var $has_one = array('user');

[eluser]Damir Sivic[/eluser]
Code:
class User extends DataMapper {

var $has_many = array( 'page');
}


class Page extends DataMapper {

var $has_one = array( 'user');
}

this is many to one...

[eluser]kakallatt[/eluser]
[quote author="Damir Sivic" date="1367940358"]
Code:
class User extends DataMapper {

var $has_many = array( 'page');
}


class Page extends DataMapper {

var $has_one = array( 'user');
}

this is many to one...[/quote]

I edited:
Code:
class User extends DataMapper {

var $has_one = array( 'page');
}


class Page extends DataMapper {

var $has_one = array( 'user');
}

But I still got error:
Code:
Table 'cms.pages_users' doesn't exist

DELETE FROM `pages_users` WHERE `user_id` = 22




Theme © iAndrew 2016 - Forum software by © MyBB