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

[eluser]bobosayhello[/eluser]
[quote author="NachoF" date="1266618956"]It doesnt require a join table... just for n to n relations[/quote]

Thank you very much for pointing this out. I made a mistake. DMZ does not require a joining table for a 1:N relationship while it seems to be the case for the original version of DataMapper.

[eluser]BaRzO[/eluser]
@Conerck
When I use with $c->region_name or $c->name it does not work.
I have changed it like $city->region_name It's works but get only one region.
Is it possible I don't know, the problem is the sql query maybe there is a LIMIT 1 for region


Code:
$regions = new Region();
        $regions->order_by('name')->get();

        $city = new City();

        $city->include_related('region', array('id', 'name', 'status'));
        $city->order_by_related('region', 'name', 'ASC'); // order by region first
        $city->order_by('name', 'ASC'); // then by city name
        $city->get();

        $city_index = 0;
        $total_cities = count($city->all);

        foreach($regions->all as $r) {
            echo('<span style="color:green">'.$city->region_name.'<br></span>');
            while(($city_index < $total_cities) &&
                    ($city->all[$city_index]->region_name == $r->name)) {
                $c = $city->all[$city_index];
                // output city info
                echo('<span style="color:red">'.$c->name.', </span>');
                $city_index++;
            }
            echo '<hr>';
        }

[eluser]Conerck[/eluser]
[quote author="BaRzO" date="1266677821"]@Conerck
When I use with $c->region_name or $c->name it does not work.
I have changed it like $city->region_name It's works but get only one region.
Is it possible I don't know, the problem is the sql query maybe there is a LIMIT 1 for region
[/quote]

It should be
$r->name

The $r variable holds the Region data. The $c variable holds the City data.

The LIMIT 1 queries are not the problem. They are made by DMZ to find out what fields are in your tables.

EDIT: You should also take a look at the Model-View-Controller-Pattern

[eluser]BaRzO[/eluser]
Thanks you are very careful. :red:

[eluser]OverZealous[/eluser]
@BaRzO, Conerck

I feel this is my fault. I need to stop that bad habit of using single-letter variables in example code! (I never would do it in production, so why do it in examples?) :-P

Have a good weekend, everyone. I'll probably be polishing 1.7 this weekend, and I'll put out a beta release for a little while first, so everyone can see if I missed anything.

[eluser]BaRzO[/eluser]
Thank you Phil, Have a nice weekend,

[eluser]Peet86[/eluser]
Hi Phil!

I have a problem with DMZ 1.6.2..
I have two model:
Media
Post

I try to join this way:
$p->media...

I get this error:
Code:
Unknown column 'mw_join_medias_posts.medium_id' in 'on clause'

SELECT `mw_medias`.*, `mw_join_medias_posts`.`media_id` AS join_media_id, `mw_join_medias_posts`.`type` AS join_type, `mw_join_medias_posts`.`meta` AS join_meta FROM (`mw_medias`) LEFT OUTER JOIN `mw_join_medias_posts` as mw_join_medias_posts ON `mw_medias`.`id` = `mw_join_medias_posts`.`medium_id` LEFT OUTER JOIN `mw_posts` as mw_posts ON `mw_posts`.`id` = `mw_join_medias_posts`.`post_id` WHERE `mw_posts`.`id` = '184'

MEDIUM?? WTF? Smile
Can you help me?

Peter

[eluser]OverZealous[/eluser]
@Peet86

It's the inflector helper, as described at the bottom of this page. It is automatically attempting to pluralize media[/]b to [b]medium. (Also, make sure you are using the updated Inflector helper provided with DMZ.)

You just need to defined both $model='media' and $table='medias' in your model definition.

[eluser]Peet86[/eluser]
Thanks Phil!
It works now!

One more question:
I have multiple relation between Media and Post..
The relations have "type" join field.
Can I add some where() term for the join field when I delete?


Code:
$n = new Post();
        $n->where("id",$parameters[0])->get();
        
        $d = new Post();
        $d->where("id",$parameters[0])->get();
        $d->media->where_join_field($n,"type",$type)->get();
        foreach($d->media->all as $image){
            $n->delete($image);  // this will delete all the relations of an image, but I only want to delete the image which has the value "$type" in the join field
        }

Peter

[eluser]Mosselmaniac[/eluser]
Hello everybody,

First post on the forum. I'm new to CodeIgniter. In fact, I'm planning to use a PHP framework for an upcoming project. CodeIgniter seems interesting at first glance, but I need an ORM to make life easier. That's why I came the "DataMapper OverZealous Edition". But before I commit myself into using these two projects, I have a question:

Is it possible with this ORM to generate the objects from the database-definition? So, I define my tables in a structured way, I define my foreign keys (relationships), then I can imagine it would be possible to generate the models. (incl. getters / setters). That will gain me a huge amount of time.

The other way around would be workable too, I code my models and call some kind of method that is generating the applicable database representation. For example, Author and Book have a many-to-many-relationship. I'm looking for something that automatically generates the join-table between the two. Or visa versa.

I've looked into the user guide of both CI and DMZ. I tried to use the search-feature, but couldn't find any related questions. I'm probably wrong, because this looks like question number #1 to me ;-) Correct me if i'm wrong, any help is appreciated.

Thank you in advance.




Theme © iAndrew 2016 - Forum software by © MyBB