![]() |
[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 - 06-25-2009 [eluser]OverZealous[/eluser] You can try to eliminate the ID column, and then set up the primary key on all remaining relationship columns (usually there will just be two). That should work. Again, DMZ doesn't use the id column for anything. The issue you described with saving it as NULL then updating it primarily shows up with in-table foreign keys. Currently there is no easy way around this, but you could try making the FK optionally NULL (for example, in PostGreSQL you can add ON DELETE SET NULL to the FK definition). The number one reason I haven't bothered with FK restraints id the fact that it can slow down inserts and updates, and provides no optimization benefits (at least on PostGreSQL) for queries. Since I only write to the DB through DMZ, and I always use transactions, there is very little possibility for corruption. The big exception to that would be some kind of weird asynchronous update from multiple users, but large transaction blocks should help reduce that risk. However, I am aware that this is bad database design, as the FK rules provide an extremely low-level check to make sure you don't break anything... ![]() [Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 06-26-2009 [eluser]Neeraj Kumar[/eluser] i accidently posted the post again... ![]() [quote author="OverZealous.com" date="1245966575"]@Codemaster Snake I'm a little confused by your description: Is your relationship this: Quote:* People have many qualifications, qualifications have one personOr this: Quote:* People have one qualification, qualifications have many people Or something else? You example doesn't make that clear. This really matters because you can only perform certain optimizations on $has_one relationships.[/quote] well this is correct: Quote:* People have many qualifications, qualifications have one person beside these there are following join tables: peoples_qualifications and degrees_qualifications [Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 06-26-2009 [eluser]OverZealous[/eluser] @Codemaster Snake In that case, the trick is to query the middle item, and join the outer items. (The join_fields methods won't help, in this case, because those would only work on data stored on peoples_qualifications or degrees_qualifications.) In other words: Code: $p = ... // look up person If you want to get all users and their degrees based on a specific qualification attribute, try this: Code: $q = new Qualification(); Updated to fix mistake pointed out by bEz below. [Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 06-26-2009 [eluser]bEz[/eluser] [quote author="OverZealous.com" date="1246060824"] If you want to get all users and their degrees based on a specific qualification attribute, try this: Code: $q = new Qualification(); Either I'm missing something, or you're kinda busy and overlooked the example code above. Should it not be: Code: foreach($q->all as $result) { [Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 06-26-2009 [eluser]OverZealous[/eluser] DOH! Man, I need more sleep... [Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 06-26-2009 [eluser]bEz[/eluser] No problem, you're support has given me more opportunity to sleep lately. Just wanted to tidy it up for ya! ![]() [Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 06-27-2009 [eluser]qureshi[/eluser] Hi! How do I solve this one: A user can have many categories. Categories have one parent category. For example user X can have a parent category Science and a subcategory Biology. How would I check if the subcategory Biology exists in the parent category Science, while at the same time ensuring that both categories belong to user X? Because another user Y might also have Science and Biology in parent-subcategory relationship, and I wish to avoid false positives. Been tinkering with this for a while, with no luck. Regards, Nadeem Qureshi [Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 06-27-2009 [eluser]OverZealous[/eluser] @qureshi Well, some of it depends on how you set it up. For example, is it important that "Science" and "Biology" be shared? Or can each person have their own copies? If the latter is the case, then that makes it much simpler (because you can store the ownership directly on the Category table). If you know for a fact that this is a one level tree, and that, for example, Biology cannot have children, you might be able to reduce complexity by not storing it as a tree at all. Instead store them as separate MainCategory and SubCategory models (which might still be able to be stored on the same table). Also, how is it possible that someone could have a child category in a parent category that they don't have access to? I think your real problem here is that that is even possible. I would look at only checking the child categories, and then assuming that the parent category is allowed if the child is allowed. It makes more sense to optimize the looking up of Categories (which is likely to be a 100x increase in usage) by making editing and changing slightly more complicated. For example, if a user loses access rights to a parent category, that is the time to remove their access rights for the subcategories. If you have to check the parent and child categories, you probably should just check them manually, after loading in the children. It should be possible to only load in child categories that belong to a specific user, then load in the parent category for each child to verify it. If you can provide more information, such as how you are storing the relationships, and how you are currently looking them up, I might be able to help you narrow it down further. [Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 06-27-2009 [eluser]qureshi[/eluser] Hi again, This: Code: $user->category->where('id', $category->where('name', $name)->get()->id)->count(); Produces this: Code: A Database Error Occurred While I think it should be: Code: SELECT COUNT(*) AS `numrows` FROM (`categories_users`) WHERE `category_id` = '286' AND `user_id` = '3' What is going on? Nadeem Qureshi [Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 06-27-2009 [eluser]OverZealous[/eluser] First off, that query will always return 1. It cannot, and will not, ever return more than one. So that's part of the issue. Second, ->count has a slightly reduced functionality, in order to allow it to use the COUNT(*) method. Update: I should have mentioned you might have gotten a non-error result using: Code: $category = new Category(); I realize you are probably trying to see if the item exists. Another method for doing this is: Code: $exists = $user->category->where('id', $id)->select('id')->get()->exists(); Which I do realize isn't quite as clean or efficient as using count(). |