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

[eluser]WanWizard[/eluser]
You're confusing a business process (the ordering of products) with a database relation. You can relate two objects of a given model only once, like any two people can only married to each other once at the same time.

If you want to record how many items of this product where in this order, record the quantity in the joining table, as it is a property of the relation. Look up "join_fields" in the docs.

[eluser]Damir Sivic[/eluser]
I just installed mysql 5.6.10.1, and on INSERT this error shows
Code:
Error Number: 1366

Incorrect integer value: '' for column 'id' at row 1



I get the same error when safe mode is off...

PS: I use $object->from_array($array)->save();

please help...

[eluser]WanWizard[/eluser]
You can setup a validation rule that will run intval() on the 'id' column, to deal with MySQL STRICT MODE.

[eluser]Damir Sivic[/eluser]
my bad, after I turn off mysql strict mode, I forgot to switch $db['default']['stricton'] to FALSE...

but isn't this problem, that queries does not succedes because strict mode is ON

[eluser]WanWizard[/eluser]
Datamapper is not aware of the strict mode that you have defined on your RDBMS. It's code is over 5 years old, long before there was such a thing.

Datamapper also doesn't generate it's own SQL, it uses CI's database layer to do so, so that needs to be configured properly as you have noticed.

[eluser]spectro200[/eluser]
Hi,relations need to create foreign-keys?
must be done manually? or handles them DataMapper

[eluser]Stolz[/eluser]
I'm using the latest tip version from Bitbucket and I'm having a problem with an advanced relationship. I can save/delete in one direction but in the other one I can delete but not save.

The project I'm working on is about TV Shows. One user can follow many shows and one show can be followed by many users. A show can be followed only once by the same user.

My intention is to be able to do something like this:
Code:
$show = new Show(111);
$user = new User(222);

//Get all users that follow Show 111
$show->follower->get();

//Get all shows that User 222 follows
$user->follow->get();


Here are the models:

Code:
class User extends DataMapper {
    public $has_many = array('
        'follow' => array('
            class' => 'show',
            'other_field' => 'follower',
            'join_self_as' => 'user',
            'join_other_as' => 'show',
            'join_table' => 'shows_followers'
    ));
}

class Show extends DataMapper {
    public $has_many = array(
        'follower' => array(
            'class' => 'user',
            'other_field' => 'follow',
            'join_self_as' => 'show',
            'join_other_as' => 'user',
            'join_table' => 'shows_followers'
    ));
}

The join table looks like:
Code:
CREATE shows_followers (
id INT(10) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
show_id SMALLINT(5) unsigned /*I-T-F-k*/, FOREIGN KEY (show_id) REFERENCES shows(id),
user_id SMALLINT(5) UNSIGNED /*I-T-F-k*/, FOREIGN KEY (user_id) REFERENCES users(id),
UNIQUE(show_id, user_id)
) ENGINE=InnoDB;

If I try user 222 to follow show 111 like this, everything works
Code:
$show = new Show(111);
$user = new User(222);

$show->delete_follower($user); //Unfollow
$show->save_follower($user); //Follow

but if I try the same action just in the opposite direction it doesn't work
Code:
$show = new Show(111);
$user = new User(222);

$user->delete_follow($show); //Unfollow (this code works! it generates the proper query)
$user->save_follow($show); //Follow (this is where I get the error)

The error I get when I run $user->save_follow($show) is
Quote:Fatal error: Class name must be a valid object or a string in application/libraries/datamapper.php on line 2461

The problem is DM is trying to create an instance of NULL class, which obviously doesn't exist. The class name comes from the DM function get_related_properties($related_field) which is returning a NULL value. That means DM thinks there is no relation between the objects so I guess there is something wrong with my advanced relationship definition.

What did I do wrong?

Thanks.

[eluser]kakallatt[/eluser]
I'm using DATAMAPPER ORM V1.8.2. I have a question for from_array method:

Firstly, I have a dropdown with name="group_id"
Code:
<select name="group_id" class="small-input">
      <option value="1">Guest</option>
      <option value="2" selected="selected">Member</option>
      <option value="3">Manager</option>
       <option value="4">Administrator</option>
</select>

In table users (database), I have a field named: group_id.

In controller:
Code:
....
$user->from_array($_POST, array('username', 'email', 'status', 'group_id'));
....
// then save
....

All things is OK.

But when I pass third parameter of from_array() is TRUE to save immediately, like:
Code:
$user->from_array($_POST, array('username', 'email', 'status', 'group_id', TRUE));

I received 1 message: The Group relationship is required, while the group input has completed.
Please help me, thank you.

[eluser]Maglok[/eluser]
Random guess: $_POST['group_id'][0]? It does that sometimes with some input elements.

Otherwise maybe you can do a print_r() on the POST array to see if it has the value and if so in what format it is in the POST.

[eluser]kakallatt[/eluser]
[quote author="Maglok" date="1366027546"]Random guess: $_POST['group_id'][0]? It does that sometimes with some input elements.

Otherwise maybe you can do a print_r() on the POST array to see if it has the value and if so in what format it is in the POST.[/quote]

I received 1 message: The Group relationship is required., while the group input has completed.




Theme © iAndrew 2016 - Forum software by © MyBB