![]() |
[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22) +--- Thread: [Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) (/showthread.php?tid=18196) |
[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 10-05-2009 [eluser]KSiimson[/eluser] I have a list of countries, and a list of objects. I also have an array of countries to be associated with the object. If I use just save(), then the relationships will be added. The old relationship will stay intact, which is not what I want. What would be the best approach to delete all the relationships associated with an object? It seems to me that I would need a list of countries that I want to remove, but I am not sure it is necessary? [Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 10-05-2009 [eluser]OverZealous[/eluser] [quote author="KSiimson" date="1254780618"]What would be the best approach to delete all the relationships associated with an object?[/quote] There are several ways. You can first unrelated all of them, then save the new ones (fine for small numbers of related items): Code: $countries = $object->country->select('id')->get(); You could also write some code to loop through the list of countries, removing the old ones, and then saving the new ones (better if you have more than 5 or so related items): Code: $new_country_ids = array(...); // array of IDs In the end, DMZ has to remove each non-related object, and then add each new object. In the background, DMZ does some cleanup work. [Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 10-06-2009 [eluser]Jeffrey Lasut[/eluser] @Jinkusu After playing with the code this made it work for me in DMZ: Code: class Product extends Datamapper [Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 10-06-2009 [eluser]OverZealous[/eluser] I'll be interested in hearing how this works for you. I've had trouble in the past using inheritance (I've got one inherited class in my app, and it causes headaches), which is why I always recommend against it. If you get it working well (including querying, saving, and deleting), and wouldn't mind, I'd love to see some examples and possibly include them in the documentation at a later date. [Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 10-06-2009 [eluser]Jeffrey Lasut[/eluser] @OverZealous No problem, I'm planning to test the various options in DMZ. When I'm done I'll post the results or questions :-) [Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 10-07-2009 [eluser]Jeffrey Lasut[/eluser] @OverZealous Just like I promised a working example, but I didn't try all the DMZ features. So there is still some testing to do. Please send me any feedback. Jeffrey edit: - some code cleaning - added db test records [Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 10-07-2009 [eluser]Jeffrey Lasut[/eluser] How do I handle a join with multiple conditions in DMZ style? This is the query that I want as a result: Code: SELECT Thanks again! Jeffrey [Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 10-07-2009 [eluser]OverZealous[/eluser] @Jeffrey Lasut You just query them, like in AR. You might be wondering about deep relationships. It's in the docs, but here's an example: Code: // get your category first, because you can only run one query at a time. I'm using different methods to handle the related items. You can choose, for consistently, to always use this form instead: Code: where_related($related_field, $column, $value); You can also chain the methods. [Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 10-08-2009 [eluser]Jeffrey Lasut[/eluser] @OverZealous Thanks for the reply! It's actually easier than I expected, yesterday somehow I just couldn’t wrap my mind around it. [Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 10-08-2009 [eluser]OverZealous[/eluser] Dang you fixed your typo to quick (yes, I caught it ;-) ). I was going to write a rap about D-M-Z's complex-i-ty. :lol: |