Welcome Guest, Not a member yet? Register   Sign In
[Deprecated] DMZ 1.6.2 (DataMapper OverZealous Edition)

[eluser]cube1893[/eluser]
I know that I'm not testing the save() method. For testing the transactions, I want to rollback the transaction even if the object saving was successfull.

One more thing: When I var_dump $f->trans_status(), it returns NULL.

[eluser]Federico Gonzalez[/eluser]
Hi,
I want to update a multiple relationship (without first deleting and then saving). I receive a multiple checkbox from $_POST, like this:

In model
class Language .... $has_many = array("country") ...}
class Country ... $has_many = array("language") ...}

In view
<input type="checkbox" name="countries[]" value="x" />

In controller
What have I to do in the controller?

Thanks

[eluser]OverZealous[/eluser]
You can see examples of how to save relationships by looking at the source to the Array extension.

It isn't really that complicated, however. You just query all of the currently related items, then loop through twice. Finally, save the new items.

Loop once to remove any items that are not in the new list.
Loop again to determine what IDs are new.

Then, look up each new item, and save it in an array back to the parent object.

Don't forget you can save a lot of time by calling select('id') before getting any relationship, since you only care about relating the items (not writing them out).

[eluser]tdktank59[/eluser]
Hey OverZealous.

So got a quick question. May be covered in the docs but not sure.

So ive got users and normaly they all will have roles. But new users will not.
So I need to be able to pull all users that do not have a role.

Users <- Many to Many -> Roles

Ill be working on a work around where I will loop through the users and ones without roles ill pass on to the view but would be sweet if there was a way dmz could do this if it exists!

[eluser]OverZealous[/eluser]
It might not be in the docs, but usually it is something like this:
Code:
$u = new User();
$u->where_related_role('id', NULL);
$u->get();

Give it a shot, let me know if it doesn't work for you. You might have to play around with it, and look a the query generated.

[eluser]tdktank59[/eluser]
[quote author="OverZealous" date="1264333917"]It might not be in the docs, but usually it is something like this:
Code:
$u = new User();
$u->where_related_role('id', NULL);
$u->get();

Give it a shot, let me know if it doesn't work for you. You might have to play around with it, and look a the query generated.[/quote]

Duh... Didn't click in my mind to use null in the related role...
Was thinking more like where_not_in... separate train of thought.
Thanks for the fix and it works btw!

[eluser]Unknown[/eluser]
Hi Phil,

First of all, great work, and great support.

I just switched over to DMZ for a project, and now I'm getting some strange behavior re: escaping of SQL functions. A bit of code using select_max() worked using DM but now is borked. I saw your last post on this topic (http://ellislab.com/forums/viewreply/699007/) and tried to implement the $this->func('FUNCNAME', '@columnname'), but with no luck.

Here's what I had at first, and the generated SQL:
Code:
class Measurement extends DataMapper
{
...
    function get_max_timestamp($unix_timestamp = TRUE)
    {
        $this->select_max('timestamp')->get();
        
        $this->load->helper('date');
        return $unix_timestamp ? mysql_to_unix($this->timestamp) : $this->timestamp;
    }
}

//SQL
SELECT `MAX(`measurements`.`timestamp`)` AS timestamp FROM (`measurements`)

//and got the error:
Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`.`timestamp`)` AS timestamp FROM (`measurements`)' at line 1

I changed the select_max() to use select_func() but get:
Code:
$this->select_func('MAX', '@timestamp')->get();

//SQL
SELECT MAX() AS @timestamp FROM (`measurements`)

I also tried:
Code:
$this->select_func('MAX', 'timestamp')->get();

//SQL
SELECT MAX() AS timestamp FROM (`measurements`)

and finally:
Code:
$this->select_func('MAX(\'timestamp\')', 'timestamp')->get();

//SQL
SELECT MAX('timestamp')() AS timestamp FROM (`measurements`)

I ended up just using:
Code:
$this->select('MAX(`timestamp`)')->get();

but this seems less than preferable. Am I missing something obvious here?

Thanks!
Spike B

[eluser]OverZealous[/eluser]
@ocelot

There's nothing that should have changed between DM and DMZ regarding the select_XXX functions and field protection. I just checked it, and the function works fine, both on Postgres and MySQL.

Check the troubleshooting section of the manual, and verify the version of CodeIgniter you are using.

Also, you are using the select_func method wrong. Read the manual again - you must include a parameter to represent the alias:
Code:
$this->select_func('MAX', '@timestamp', 'timestamp');

[eluser]Alface[/eluser]
I had been facing a problem for a long time with "HTML Form Generation Methods (htmlform) Extension".
The code is:
Code:
class Company extends DataMapper {
    var $has_many = array(
            'telephone' => array(
                'class' => 'telephone',
                   'other_field' => 'user'
            )
    );
    var $validation = array(
        'cname' => array(
            'label' => 'Company name',
            'type' => 'mult'
        ),
        'user' => array(
            'label' => 'Users'
        )
        );
[...]
}
Code:
class User extends DataMapper {
    var $has_one = array(
            'user' => array(
                'class' => 'user',
                   'other_field' => 'telephone'
            )
    );
    var $validation = array(
        'name' => array(
            'label' => 'Name',
            'rules' => array('trim')
        ),
        'email' => array(
            'label' => 'Email',
            'rules' => array('trim')
        )
    );

[...]
}

The problem:
I would like for it to instead of showing a drowdown for the itens from the database, show an input for the User 'name' and a button "More user", and include another row of inputs.
I know I will need a JS script, and I already have it. But I think I could use the render functions of htmlform Extension.

Has anyone one been through this before?

[eluser]OverZealous[/eluser]
@Alface

The HTMLForm extension has the ability to call any public method. I believe it is in the docs under Custom Inputs.




Theme © iAndrew 2016 - Forum software by © MyBB