[eluser]ben_co[/eluser]
Quote:Are you simply not wanting to create the object manually?
Exactly. In my examples, I would only create objects when I work on a specified (set of) records. For bulk (update or delete), we shouldn't need in my opinion to create an empty record because we don't want to populate it with/or execute a query on a resultset.
Quote:You have to instantiate at least one copy of every model just to figure out what the table name is.
I know that. It's why in my examples my code would behave like this:
Code:
$this->datamapper->load('articles');
$newstype = new Type(3);
$twoweeks = 1209600;
$this->articles->where_related('type', $newstype)->where('created <', time()-$twoweeks)->bulk_update(array('oldarticle', TRUE)); ;
But I admit that $this->articles is in fact the same that $articles = new Article();
The second problem is that save() and delete() shouldn't be callable directly in my opinion. It should be only when we plan to create a new record or modify an existing one. In the following example, these methods are useless.
Code:
$this->articles->delete(); // equivalent to: $article = new Article(); $article->delete();
delete() should delete all the articles, not throw an error about 'no record selected'.
And in this last example,
Code:
$this->articles->new_record(); $article->delete();
delete() would throw error about 'not specified datas' only.
I hope my explanations are clear ;-).
To sum up my ideas, on one hand, when we create a DMZ model instance, we should only apply bluk operations.
On the other hand, specific save() and delete() are available when we manipulate (a set of) existing (or new via the create_new() method) records based on the DMZ model definition. DMZ model definitions should so be considered as a singleton class (and only as a factory).
Finally, maybe it's just a problem of notation habit :-). Never mind, forget that ;-) !