Welcome Guest, Not a member yet? Register   Sign In
DataMapper ORM v1.8.1
#11

[eluser]WanWizard[/eluser]
Correct. Zips have been recreated, repository tag v1.8.1. has been moved up to include the fixes.
#12

[eluser]Steve Wanless[/eluser]
Question about deleting relationships.

I want to relate Object_A to many Object_B with a series of checkboxes. If it's checked, make the relationship.

But when I want to edit the relationships I need a way of deleting the relationships, but leaving the object itself intact.

Is there an easier way than getting all the existing relationships, deleting them all, then going through the new list and creating the relationships again.


Thanks WanWizard for continuing the development of this awesome ORM!!
#13

[eluser]benboi[/eluser]
When i validate completely using my forms and i dont want to rewrite the same rules for my orm-model, how am i able to write data into the database?

My class:

Code:
class User extends DataMapper {
    
    var $table = 'user';
    var $has_one = array('group');
    
    var $validation = array();
    
    /*
     * validates if given passwort belongs to user
     * @access public
     * @param $username string
     * @param $password string
     */
    public function validate($username, $password) {
        $user = $this->where('username', $username)->get();
        if($user) {
            $userPassword = $user->password;
            if(sha1($password) == $userPassword) {
                return true;
            }
        }
        return false;
    }

In the controller i do the following:

Code:
$userInput = $this->add_user_form->post();

                $newUser = new User();
                $newUser->username = $userInput->username;
                $newUser->title = $userInput->title;
                $newUser->prename = $userInput->prename;
                $newUser->name = $userInput->name;
                $newUser->email = $userInput->email;
                $newUser->password = sha1($userInput->password);
                $newUser->group_id = $userInput->group;

                $newUser->skip_validation()->save();

I get the following error: You must use the "set" method to update an entry.

There is nothing inside the user table, which could be updatet. What is wrong?

PS: using v1.8.1
#14

[eluser]WanWizard[/eluser]
@Steve,

No, there isn't. But you'll have to retrieve the current relations anyway, to be able to prepopulate the checkboxes.
You can use that result to delete then as well.
#15

[eluser]benboi[/eluser]
My aim is to just write the validated form-values to the database without validating them again against the same rules.

Is this possible?
#16

[eluser]WanWizard[/eluser]
@benboi,

You haven't defined any validation rules in your model, so no skip_validation() is needed.

The save() method does an UPDATE when $modelobject->id contains a value, and an INSERT if it's NULL. Is this all your code, or are you assigning a value to the 'id' field somehwere?

The idea behind model validation is that you don't have to do that in your controllers. No matter where in your application you update a model, the validation is run. If you do it in your controllers, you have to add validation code everywhere you're updating the model.

Which will become a maintenance nightmare if your application has any size, and you add or change your table structure, you'll have to scan your code to update all your controller-based validation code.
#17

[eluser]benboi[/eluser]
Hello,

im not assigning an id to the "User"-object. I just made a var_dump on that attribute and it returns NULL, so an insert must be done by DataMapper, but it doesnt.

When i write data manually to the data-table, my data can be read using

Code:
$users = new User();
$users->get();

I don't understand the problem...

Thanks for your help Wink
#18

[eluser]WanWizard[/eluser]
I can't reproduce it.
Code:
$test = new Test();
$test->field = 'value';
$test->save();
just inserts the record and assigns the insert_id() to $test->id.

When you force an insert, does that work:
Code:
$test->save_as_new();
just to verify nothing else is broken?

Which version of CI are you using? Which database driver?
#19

[eluser]benboi[/eluser]
The force to save didnt work too ....

Hmmm, just created a new User object and just set name = 'foo', not even that is getting saved :/

Im Using the current CI-Reactor and Mysql as driver.

Is it maybe because of the has_one connection to group?
#20

[eluser]WanWizard[/eluser]
No, there doesn't seem to be anything wrong with your code.

Is error_reporting enabled? If not, any PHP errors, notices, warnings, in your logs?

What's the output of $newUser->check_last_query() after you have called save()?




Theme © iAndrew 2016 - Forum software by © MyBB