Welcome Guest, Not a member yet? Register   Sign In
DMZ 1.7.1 (DataMapper OverZealous Edition)

[eluser]OverZealous[/eluser]
@introvert
I don't know how hard it will be, but I'll look into it. I might have to rewrite save() so that if the updated field has been manually changed, then the object will save even if nothing else has changed.

[eluser]introvert[/eluser]
Why wont this work:

Code:
public function update_timestamp() {
        $timestamp = $this->_get_generated_timestamp();
        
        // Check if object has an 'updated' field
        if (in_array($this->updated_field, $this->fields))
        {
            // Update updated datetime
            $this->{$this->updated_field} = $timestamp;
        }
    }

Code:
$object->update_timestamp();
$object->save();

[eluser]OverZealous[/eluser]
@introvert

Check out how the save() function works. Currently, if the only changed field is the updated field, then it doesn't bother saving. (In fact, it rolls back the change to the updated field.)

It's a leftover decision from long ago. I've actually thought about changing it, but it's not a high priority thing. Most people just use it the way it currently works, automagically. ;-)

[eluser]macigniter[/eluser]
I got a question which I am sure was answered here before. But since the search function in this forum isn't that great *duck* I am asking it here:

Is there an easy way of detecting whether a dataset is related to any other table as defined in the models?

Let's say I have a "currencies" table with multiple rows:
1 USD
2 EUR
...

Now before I allow to delete a currency I would like to check if that currency is somewhere related in any of the other tables (e.g. prices, invoices, etc.). Since all relations are stored in the models I am sure there is an easier way of doing this:

$c = new Currency();
$c->get_by_name('USD');

if ( ! $c->price->count() && ! $c->invoice->count() && ...) $c->delete();

Something like $c->is_related() would be awesome. To check whether $c is related to any dataset in the related tables as defined in the models...

[eluser]OverZealous[/eluser]
[quote author="macigniter" date="1273681608"]I got a question which I am sure was answered here before. But since the search function in this forum isn't that great *duck* I am asking it here:[/quote]

Did you try the search in the manual? It searches these forums as well. It's backed by Google™

Quote:Is there an easy way of detecting whether a dataset is related to any other table as defined in the models?
Why don't you just write an extension. All the relationships are stored in the $has_one and $has_many arrays. Simply loop through the keys on those arrays, and do your count checks. Note that is_related_to already exists, so it might be confusing to call it is_related.
Code:
function is_related_to_anything($object) {
    $result = FALSE;
    foreach(array($object->has_one, $object->has_many) as $arr) {
        foreach($arr as $rel => $props) {
            $result = $object->{$rel}->count() > 0;
            if($result) {
                break;
            }
        }
        if($result) {
            break;
        }
    }
    return $result;
}

Wrap that up in an extension, and you can share it with others, as well as use it on any model you want.

[eluser]Wazzu[/eluser]
Maybe "Query related models" topic may help you:
http://www.overzealous.com/dmz/pages/get...l#_related
So you can make a count() on it to ckeck if relation exist

[eluser]macigniter[/eluser]
[quote author="OverZealous" date="1273683107"]
Did you try the search in the manual? It searches these forums as well. It's backed by Google™
[/quote]
No. Thanks for the hint!

[quote author="OverZealous" date="1273683107"]
Why don't you just write an extension. All the relationships are stored in the $has_one and $has_many arrays. Simply loop through the keys on those arrays, and do your count checks. Note that is_related_to already exists, so it might be confusing to call it is_related.[/quote]

Thanks, Phil. I'll give that a try. You should get an award for always replying so fast... :-)

EDIT: It rocks! Man how I love you for creating this amazing piece of code...

[eluser]Unknown[/eluser]
DMZ works really well for everything so far, and it's been very useful.

I have a question about the many-to-many relationship for the table setups though. In the examples, http://overzealous.com/dmz/pages/relationtypes.html, there's a skill_workers many-to-many relationship:

skills_workers
id skill_id worker_id

Why does that table have its own ID? There's no point to having duplicate data, so you might as well just set the primary key to the skill_id and worker_id. Browsing through the DataMapper class, it seems to be ok with not having that extraneous id field, am I right in assuming that it's not necessary?

[eluser]OverZealous[/eluser]
@leo_
It is not necessary, but it is good database design. Every table should have a unique, dedicated primary key. For proper database normalization, it's not usually recommended to use composite primary keys. (I think at one time not all databases supported composite PKs, so having a dedicated PK also helped with portability.)

As you noted, DMZ does not currently use the ID. I still recommend it, and cannot guarantee that future versions of DMZ won't use the ID. There's no good argument for leaving it out, IMO, because it's a tiny integer field.

Finally, a really good argument for it, is when having multiple relationships between the same objects (scroll to Setting up the Table Structure with Advanced Relationships). In this case, there is more than just two columns on the table, and the PK is much less obvious.

[eluser]tomdelonge[/eluser]
I read real quickly about get_paged and get_paged_iterated. For some reason, get_paged() works fine. If I try get_paged_iterated() it gets screwed up. Wherever the loop was, nothing gets outputted. The rest of the page is outputs just fine, and as far as I can tell, no php errors are showing up.

Any ideas on why it won't work?




Theme © iAndrew 2016 - Forum software by © MyBB