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

[eluser]WanWizard[/eluser]
Why not? Works perfectly here. It even supports the new 2.0 packages.

Do you get any error messages?

[eluser]patie[/eluser]
[quote author="WanWizard" date="1279812163"]Why not? Works perfectly here. It even supports the new 2.0 packages.

Do you get any error messages?[/quote]

yes when i delete
$this->load->model('products/products_model');

Fatal error: Class 'Products_model' not found in ******************************/modules/some_module/controllers/some_sontroller.php on line 104

i use modular separation.. this can be a problem (i think)

[eluser]OverZealous[/eluser]
@patie
If you search this topic, there have been others who are working with CI 2.0. But I'm not currently using 2.0 (and it isn't even officialy released yet, as far as I know — 1.7.2 is still on the home page).

I did add in some code that allows it to work with modules, however.

Finally, you shouldn't ever load in models manually when you are using DMZ. DMZ doesn't work with models the same way as CI.

[eluser]nottRobin[/eluser]
I've looked through the manual and played around a lot and searched on Google for about an hour but I can't find an answer to this question:

I have two models:

Code:
class model_energy_saving_bulb extends DataMapper {
    var $table = 'energy_saving_bulb';
    var $has_many = array(
        'non_energy_saving_bulb' => array('class' => 'model_non_energy_saving_bulb', 'other_field' => 'energy_saving_bulb'),
    );
}
and
Code:
class Model_non_energy_saving_bulb extends DataMapper {
    var $table = 'non_energy_saving_bulb';
    var $has_many = array(
        'energy_saving_bulb' => array('class' => 'model_energy_saving_bulb', 'other_field' => 'non_energy_saving_bulb')
    );
}

The problem is that the joining table therefore has to be called
Code:
energy_saving_bulb_non_energy_saving_bulb
which is ridiculously long. I'd rather call it
Code:
bulb_relationship
or something. Is there any way to do this?

Thanks Smile
Robin.

[eluser]OverZealous[/eluser]
@nottRobin
No. Don't give your relationships long names, and then you won't have long table names. Smile

Also, your table name actually is: energy_saving_bulbs_non_energy_saving_bulbs. You must pluralize the field names.

[eluser]WanWizard[/eluser]
@patie, @phil,

I assume that modules here refers to some kind of CI 1.x version of modular separation? In that case I think Datamapper is not aware of those directories, and will not be able to find the model files.

It works correctly with CI 2.0 packages, which I have extended to support controllers and views, so in effect a package now equals a module.

[eluser]nottRobin[/eluser]
@OverZealous

Thanks for the prompt answer. If it's not possible I'll just put up with the long table name, it doesn't matter that much.

However, you're wrong that I need to pluralise the names (I know, I've tried it), as I deliberately haven't used plurals in the table names. I don't like being forced into using nomenclature that fits in with your software - and thankfully in the case of table names, I can use:
Code:
var $table = 'energy_saving_bulb';
to get around the pluralisation.

Strangely enough it had occurred to me that if I had shorter table names then my joining table name wouldn't need to be so long. However, I don't think this is what you should be advising people to do. From a best practice point of view it is far better to have a long name that accurately describes the function of the table than a shorter one that doesn't - but my joining table would be more accurately described with a shorter name. Therefore, if you have time in the future development of DMZ, I think it would be a good idea to add a variable for customising this joining table name.

Thanks for an otherwise great piece of software Smile

[eluser]patie[/eluser]
ok thanks. and last question that not yet been answered please

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.. )

maybe with hasOne? but i dont understant about ... please help me with that last question (codeigniter with dmz datemapper rlz)

[eluser]dejavu[/eluser]
[quote author="bEz" date="1279657418"]Hey Phil,

It's been a minute since I've needed your assistance with DMZ technical issues, but as I can see, you're still providing the most informational, advantageous, superdicular, "feel free to stop me when you can," support I've ever seen.

I believe that between this thread and the legacy thread, if someone were to read each and every post, it would serve as an alternative approach to learning advanced PHP5 solutions (as related to CodeIgnter) and how to provide Technical Support (beyond the typical "Read the effing manual!" statement).

- bEz[/quote]

Amen, brother! I've been reading these threads just for the educational value. Phil is the man.

B

[eluser]WanWizard[/eluser]
[quote author="patie" date="1279832556"]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.. )[/quote]
Follow the examples in the documentation, they are clear enough.

P.e., if you have a table called 'users', and a table called 'groups', both will have a column called 'id' that identifies the record. The 'users' table will also have a column called 'group_id', linking the user to a group.

You then define a model called 'user' (singular!), which has a $has_one relationship to class 'group', and you define a model called 'group', which as a $has_many relationship to user. Because your column in the 'users' table has the name of the class ('group'), followed by the id, DMZ knows that this is the foreign key.

All you then have to do is:
Code:
$u = new User(); // create a new user object
$u->get_by_name('some_username'); // fetch the record of user "some_username"
$u->group->get(); // get the group this user belongs to

- or -

$g = new Group();  // create a new group object
$g->get_by_id(1); // get the group that has id 1
$g->user->get(); // get all users in this group




Theme © iAndrew 2016 - Forum software by © MyBB