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

[eluser]OverZealous[/eluser]
@Jamie

The short answer is, it doesn't. There is no inherent support for extending classes (yet).

That being said, you can back multiple models with a single table. It just requires a bit of work, including overriding the save and get methods to set or clear type flags.

For example, you might have a flag called is_manager, and the Employee class clears the flag when saving, and adds a where('is_manager', FALSE) when getting, and the Manager class does the opposite.

Also, all relationships have to be mapped individually for each class if you are using this technique. You will lose the ability (in the example above) to query all Employees and include all Managers at the same time.

There is a way around some of that last piece, using the advanced relationships. In my app, I have two objects, Jobs and Service Calls. A Service Call is really a special case Job. Jobs is normal, except it clears is_servicecall for saving and getting.

Now, say I have an model called Task. In Job, it is related like this:
Code:
$has_many = array('task');

function get($limit = '', $offset = '') {
    $this->where('is_servicecall', FALSE);
    parent::get($limit, $offset);
}

// important: must allow for getting any type
function get_any($limit = '', $offset = '') {
    parent::get($limit, $offset);
}

In Service Call:
Code:
var $model = 'servicecall';
var $table = 'jobs';

var $has_many = array(
    'task' => array( 'join_self_as' => 'job' );
);
function get($limit = '', $offset = '') {
    $this->where('is_servicecall', TRUE);
    // notice: calling get_any
    parent::get_any($limit, $offset);
}

In Task:
Code:
var $has_one = array(
    'job',
    'servicecall' => array('join_other_as' => 'job')
);

Now servicecall and job are both related using the same database tables, and can be queried together using get_any.

You can also automate configuring the ServiceCall model, by having a constructor like this:
Code:
static $_sc_did_config = FALSE;
function __construct($id = NULL) {
    // only configure service call properties once (it's cached for all other copies)
    if(!self::$_sc_did_config) {
        // Fix relationships
        foreach(array('has_one', 'has_many') as $f) {
            $new = array();
            foreach($this->{$f} as $field_name) {
                $new[$field_name] = array('join_self_as' => 'job');
            }
            $this->{$f} = $new;
        }
        
        self::$_sc_did_config = TRUE;
    }

    parent::__construct($id);
}

----------

In summary: It is a lot of work to maintain, and I have yet to see a great reason to use polymorphism in a DMZ-backed app. I highly recommend avoiding it if possible. Personally, I wish I had just gone with tracking the information via the flag, and skipping the polymorphic objects, but it would be a lot of work to change the current design in my app.
#12

[eluser]Michael Ditto[/eluser]
I am really enjoying the DMZ library thus far. There is a bit of a learning curve, but it's really worth it.

There's a pretty solid library in CI already for dealing with file uploads, but it's not clear to me if it's possible to use it with DMZ's built-in form generation and handling, which I'd like to use to handle all the metadata associated with an uploaded file.

Would I call the do_upload method as a validation function? If anybody could provide an example of how it might be used or comment on if it's possible or advisable, that would be great.
#13

[eluser]Unknown[/eluser]
For Subquery function

Does it support multi time subquery for same data object?
#14

[eluser]OverZealous[/eluser]
[quote author="SH Chung" date="1259745624"]For Subquery function

Does it support multi time subquery for same data object?[/quote]

I'm not sure if this is what you are asking, so correct me if I'm wrong.

The subquery functionality allows you to create multiple subqueries on different Objects. It doesn't matter if they have the same Class.

For example, this would work:
Code:
// You can now interleave multiple queries
$user1 = new User();
$user2 = new User();

$user1->where('name', 'Fred');
$user2->where('name', 'Bob');

$user1->get();
$user2->get();

This, however, will not work, because there is only one query object:
Code:
// WILL NOT RETURN ANYTHING!!!
$user1 = new User();

$user1->where('name', 'Fred');
$user1->where('name', 'Bob');

$user1->get();

(I know those aren't subqueries.)

And, of course, you can use different Classes without an issue. What this means is that you should be able to perform subqueries with self-related objects.
#15

[eluser]macigniter[/eluser]
Hi Phil, what do you think of an RSS feed to subscribe for the changelog / version updates? That'd be cool! (or did I miss an existing one?)
#16

[eluser]BrianDHall[/eluser]
Hiya Phil, just came up with something useful to suggest. I would like, and think other people might find it useful, to have a more full _template.php provided with some of the other configuration options available. I just happened upon the part of the manual that explains the custom error wrappers for forms, and at the bottom of Validation page I noticed you could over-ride them on a per-object basis. Just as an example, but if this were provided in commented fashion like with other features shown in the template, I'd have noticed them much sooner Smile

Would be nice to have any other interesting configuration variables shown in template too, if there should happen to be any. I'm getting to the point that I prefer reading code over reading manuals Smile
#17

[eluser]OverZealous[/eluser]
[quote author="macigniter" date="1259949716"]Hi Phil, what do you think of an RSS feed to subscribe for the changelog / version updates?[/quote]

Hmmm. I could look into this. As it is every time I make an update, though, I have to:
• Update the manual (and put it on the website)
• Deprecate the existing forum
• Create a new forum
• Re-update the manual with the new forum's link
• Update my signature
• Update the CI wiki

An RSS feed would just be one more thing to update... ;-)
#18

[eluser]OverZealous[/eluser]
[quote author="BrianDHall" date="1259966216"]I would like, and think other people might find it useful, to have a more full _template.php provided with some of the other configuration options available.[/quote]

I don't have the time to flesh it out right now, but if you wanted to add anything you've come across and PM or email the update _template.php to me, I'll include the changes with the next release.
#19

[eluser]Michael Ditto[/eluser]
[quote author="Michael Ditto" date="1259708989"]I am really enjoying the DMZ library thus far. There is a bit of a learning curve, but it's really worth it.

There's a pretty solid library in CI already for dealing with file uploads, but it's not clear to me if it's possible to use it with DMZ's built-in form generation and handling, which I'd like to use to handle all the metadata associated with an uploaded file.

Would I call the do_upload method as a validation function? If anybody could provide an example of how it might be used or comment on if it's possible or advisable, that would be great.[/quote]

To answer my own question, or at least put it out of its misery, there's not as much brilliance in the CI file upload class as it seemed, at least for my purposes. I just used PHP's built-in functionality to handle that part.



As a (tangentially related) side note, this is my first foray into file uploading in a web application, and it's a user interface nightmare. In the world of desktop applications from which I come, we spend all kinds of effort customizing and hooking into OS file open dialogs to make them do wondrous things like display metadata about our files to the user to help them make an informed decision about what to open. In the web world I can't even tell the browser's file open dialog to filter by file type. I know there are some Flash options, but really... why should that be necessary? </rant>
#20

[eluser]tdktank59[/eluser]
Another great release Pill!

Now I have to go read the docs again... O well, it's all worth it in the end right?

Will update if I notice any problems.




Theme © iAndrew 2016 - Forum software by © MyBB