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

[eluser]Mirage[/eluser]
Hey Phil,

Looks we just crossed our posts. Thanks for the explanation on the table naming. I wonder if the join tables couldn't be made custom by using the key of the relationship definition:

Code:
class plant extends DataMapper {
    var $has_one = array();
    var $has_many = array(
        'plant_images' => array(
            'class' => {class},
            'other_field' => {joinfield}
        )
   );

I suppose it may not be that 'simple'.

Thanks again,
-m

[eluser]OverZealous[/eluser]
[quote author="Mirage" date="1258859508"]However, I'm still not liking that the relationship has to be called images_plants rather plants_images. Why is this?[/quote]

You probably haven't read my response yet, but answer this:

How would DMZ know you meant plants_images instead of images_plants? Would you rather that it check the database everytime you run a query?

DMZ is not a generic ORM. It only works with a very structured database with specific rules. They are all very clearly defined in the manual. This includes every table having an auto-incrementing 'id' column, specific table names, and specific join tables.

I'm not going to change it, but it might help explain it. Also, there is no reason to customize DMZ even more for something so trivial to change in the database. The method you mentioned in your last post (it just popped up) would not work because the key on the relationship arrays is the name of the relationship.

----

A relationship is between two objects. It doesn't exist on just one or the other. When you do this:
Code:
$plant->image->get();
You are actually doing this behind the scenes:
Code:
$image = new Image();
$image->where_related($plant);
$image->get();

So, Image needs to know that it is related to Plant.

[eluser]Mirage[/eluser]
Phil,

I agree with your sentiments. I'm fine the fact that DMZ defines the rules and agree that the adjustments are trivial. But as you see (perhaps it's just me) I think of modeling this a little different than others. I'll just have to adjust my way of thinking to DMZ rather than the other way around. :-)

But let me just say, that finding the tidbit about the naming rules for join tables would've been pure luck on my part. I couldn't have done this without asking and moreso - without you answering. The documentation for DMZ is clearly very complete. Yet I find myself jumping all over to try and find answers to my questions.

I don't want to sound ungrateful. I am not. I love DMZ and I'm grateful for your support.

Cheers,
-m

[eluser]chadbob[/eluser]
I'm a bit confused by extensions... I wish to use these, but I don't see the required files anywhere in the download? "views/dmz_htmlform " - It says I need this file in the docs, but I don't see it in the download anywhere?

And when I try adding the extensions array to my datamapper config I get a php override error?

[eluser]Mirage[/eluser]
Ok Phil one more...

PlantCollections can contain many plants and plants can be in many collections. A many-to-many relationship with join table 'plantcollections_plants'.

Oddity: Rather than plantcollection_id in the join table I used the column name collection_id. I set up the relationship like this
Code:
class PlantCollection extends DataMapper {
     var $has_many = array(
       'plant' => array(
           'class' => 'plant',
           'other_field' => 'collection'
       )
    );
Code:
class Plant extends DataMapper {
    var $has_many = array('image','plantcollection') ;

This setup doesn't work. From the PlantCollection perspective I get no errors, but the relationship won't save using $collection->save($plant). I assumed that the problem was my definition in the PlantModel. And proving that by calling $plant->save($collection) did indeed raise an error that the column 'plantcollection_id' was non-existent.

How would I have to define this then in the Plant model, to get it to work?

For now I solved it by renaming the column in the join table which isn't a problem in this case, but I have the feeling that there would've been another way?

Thanks,
m

[eluser]Mirage[/eluser]
Ok, got it myself. This also clears up for me the usage of the keyfield in the relation setup. This makes it go:

Code:
class PlantCollection extends DataMapper {
     var $has_many = array(
       'plant' => array(
           'class' => 'plant',
           'other_field' => 'collection'
       )
    );
Code:
class Plant extends DataMapper {
    var $has_one = array();
    var $has_many = array('image',
         'collection' => array(
           'class' => 'plantcollection',
           'other_field' => 'plant'
       )
    );

I believe to have found a bug though. Before I had Plant set up as shown above, I had tried this:
Code:
class Plant extends DataMapper {
    var $has_one = array();
    var $has_many = array('image',
         'plantcollection' => array(
           'class' => 'plantcollection',
           'other_field' => 'plant',
           'join_other_as' => 'collection'
       )
    );

That didn't work. Doco says that the default of the join_other_as value is the key of the relation. It appears that this was ignored and saving the relation failed with an error 'Failed to save relation'.

ttfn,
-m

[eluser]q.Nghia[/eluser]
Hi Phil, I've been using dmZ for months, everythings move perfectly! However, today when I upload my client's site to server, something strange happen. I did my best to search for answer through google, manual and this forum but found nothing, so if you have some time, please help me a while or show me if the problem happened and solved before Smile Lots of thanks!

Here's my problem:
- I got Brands model and Countries Model, one Brand has one Country, normal 1-1 relationship.
- In a form to add/edit Brand, i use htmlform to generate the dropdown box for Countries.
- Things work correctly locally (I use Leopard), but when publish to host, which is Windows NT, the dropdown show "Object id #xx", "Object id #xx" , "Object id #xx" ,ect... instead of country's names.
I include two screenshots of them.


@code Ignitor version: 1.7.1
@dmZ version: 1.5.4

Again, thank you! Smile
Nghia Nguyen

[eluser]q.Nghia[/eluser]
I think I found the reason ^^

PHP version of server is 5.1.6, my localhost using PHP 5.2, the __toString() of models doesn't work. But still dont know how to fix this...

[eluser]OverZealous[/eluser]
@q.Nghia

The only solution is to upgrade your server's version of PHP, or modify the htmlform extension. As it says in the docs, some extensions require a newer version of PHP.

(Win NT? Yuck! Smile )

[eluser]OverZealous[/eluser]
[quote author="chad ross" date="1258867622"]I'm a bit confused by extensions... I wish to use these, but I don't see the required files anywhere in the download? "views/dmz_htmlform " - It says I need this file in the docs, but I don't see it in the download anywhere?[/quote]

Did you download the full version? If so, everything is included in the <ZIP>/application/ folder. You need all of the files in that folder.




Theme © iAndrew 2016 - Forum software by © MyBB