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

[eluser]bEz[/eluser]
hahaha, how timely to reach your 1K....

"RTFM" however is definately not a "knock" in your case though... but eagerness of new users to install and use such a resourceful library, along with hesitation or compatibality issues to its required configuration, does create support request beyond the manual...
...however, there have been intriuging questions and solid user contributions that has allowed DMZ to evolve.

[eluser]WanWizard[/eluser]
@phil,

Are you open to feature requests? I wonder if it's possible to do something about the hideous column names generated by "include_related" and "include_join_fields". Especially if you include several levels deep, you get very long names, even though the original name is unique.

For example, I have a stucture page -> element -> module_method -> module. I need the field 'directory' from the module table, I end up with a column called 'page_element_module_method_module_directory'. Not handy to use that in your application...

[eluser]OverZealous[/eluser]
@WanWizard
Please read the documentation again.

That functionality is already included for include_related. Joins don't need it, because they only add the prefix join_.

And they aren't hideous. Smile They simply reflect the relationship structure in a way that mostly guarantees unique names, in a standardized and predictable manner. Any changes from this would lead to unpredictable results, or fields getting overwritten.

[eluser]introvert[/eluser]
Hi.

I'm doing self-relationship on a Group model.

Group can have a parent group (one-to-one relation) and has field name parent_id, which represents the group's parent.

I read the documentation and I'm unsure how to set this up.

Thats what I did:

Code:
class Group extends DataMapper {

    var $has_one = array('group');

    var $validation = array(
        'name' => array(
            'label' => 'Name',
            'rules' => array('required')
        ),
        'parent_id' => array(
            'label' => 'Parent Group',
                'class' => 'group',
                  'other_field' => 'group'
        )
    );
}

How should I set this?

I also want to be able to show form select lists with htmlform DMZ extension (so that all groups would list) and thats how I currently render the html form, but it won't show the list properly:

Code:
$form_fields = array(
            'id', // Hidden id field
            'name',
            'parent_id' => array(
                'list' => $groups
                )
);
$this->load->view('groups/edit', array('group' => $group, 'form_fields' => $form_fields, 'url' => $url));

What am I doing wrong?

Many thanks in advance.

[eluser]WanWizard[/eluser]
You should define self-relations in the has_one or has_many arrays, not in the validation array.

The 'other field' should be the column name that holds the key, which in this case I assume should be 'parent_id'.

[eluser]WanWizard[/eluser]
[quote author="OverZealous" date="1279666814"]@WanWizard
Please read the documentation again.[/quote]
You're referring to $prefix? Guess I missed that.

[eluser]OverZealous[/eluser]
@introvert

You have several problems. First, you can't use the keyword parent for anything. This is specifically highlighted in the red section at the top.

Second, the documentation for Self Relationships (scroll down) pretty much defines the exact relationship you are talking about. Instead of parent / group, it's called post / relatedpost. You'll have to come up with a different name (ie: group / parent_group), but the format should look exactly the same.

Also, it sounds like you really want a one-to-many relationship. Otherwise it's just a long chain (not a tree).

Here's the basic structure to get you started:
Code:
...
$has_one = array(
    'parent_group' => array(
        'class' => 'group',
        'other_field' => 'child_group'
    )
};

$has_many = array(
    'child_group' => array(
        'class' => 'group',
        'other_field' => 'parent_group'
    )
);
...

Your groups table needs to have a parent_group_id column.

As for using HTMLForm - I can no longer support that extension.

[eluser]patie[/eluser]
ohhh.. i discover your version of datamapper only today.. wow ... but i have question.. the model (in MVC) has lost importance for me (for "small" queries), most of the database command in the controller I have now is this normal? smile i need more examples of using this.. thanks so much

[eluser]WanWizard[/eluser]
Not really.

Instead of writing
Code:
$this->load->model('my_model');
$users = $this->my_model->get_users();
in your controller, you write
Code:
$users = new Users();
$users->get();
Doesn't make a lot of difference.

DMZ allows you to write custom methods for your models too, so anything that you use to code in your models is still possible, altough with DMZ the're probably more tied to a single table.

[eluser]patie[/eluser]
(EDITED)

thanks.. and another questions.

- model autoload dont work in 2.0 ? (i use modular separation )

- how made some like this.. simple ex. SELECT * FROM (`table`) LEFT JOIN `table2` ON `table`.`id` = `table2`.`table_id` (i read doc but i dont understand this.. )

THANKS




Theme © iAndrew 2016 - Forum software by © MyBB