![]() |
[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 - 07-10-2009 [eluser]OverZealous[/eluser] mcnux There are two solutions to your problem. 1) Since you are remapping the client to a different user, the easiest solution is to simply save the clients to the new user. Because each client can only be related to one user (both by rule AND by database design), the new $userTwo->id will be set in $client->user_id. You will still need to load the new Clients on the new User ($userTwo->client->get()) to see the update. Also, the old user will still have the related set in memory for this HTTP request (meaning, $userOne->client->all will still contain a reference). There is no way for DM to know that you are moving clients from one user to another, due to PHP garbage collection limitations. 2) $userOne->delete($client) requires that $client->user_id be able to be stored as NULL. When you set FK rules in most databases, you often need to explicitly allow NULLs, as is mentioned in the docs (under Rules). Please read over your database's docs, and make sure that your rules are not preventing the column from being set as NULL. [Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 07-11-2009 [eluser]80onelove[/eluser] Here's one I've been mulling over for a few days: I'm working on a group blogging platform. I have a table for users and a table for blogs, which are joined by table blogs_users. Users has many Blogs Blogs has many Users Now, I'd like to grant different privileges to different users on different blogs. Here's an example: User_1 is joined to Blog_1 and Blog_2, but is granted Level_2 privilege for Blog_1 and Level_4 privilege for Blog_2. Can this be achieved using DMZ? Or can it be accomplished merely using DataMapper? I've been toying around with this for a while, and the only solution I can come up with is having a privilege table with columns for user, blog, and privilege, but I'm wondering if this is redundant? [Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 07-11-2009 [eluser]OverZealous[/eluser] @80onelove It's possible, but not really practical, with the original DataMapper (it requires using a dedicated model to handle the relationships, and a lot of extra queries to look them up) With DMZ, you can easily use join fields to add one or more additional columns on blogs_users. The column could be as simple as storing a value for the access level, or the ID of a privilege model. Or you could store more complex values on the join table directly. Then you can query using that value, and include it when getting results. [Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 07-12-2009 [eluser]80onelove[/eluser] @overzealous Yep, I'm now using DMZ joins and it's working like a charm... much improved over the existing DM mapping functions. Cheers! [Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 07-12-2009 [eluser]Daniel H[/eluser] Okay I figured out my country and state problem. Basically the field_data function doesn't play nicely with db caching, which I hadn't disabled. So basically every time I need to do an 'include_related' or similar, I need to turn the db cache off and then turn it back on again. Essentially field_data returns an empty array if the cache is enabled, since the data cannot be cached. Quite frustrating! [Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 07-12-2009 [eluser]OverZealous[/eluser] For anyone wondering, this is due to the way CodeIgniter's query caching works, and is completely unrelated to DataMapper. The CI guide even explains the risks of using query caching. I actually have an extension in the pipeline (it's already built) that will allow you to easily use the above query caching without worries. (Basically, to use a cacheable query, you'd call get_cached instead of get.) That, along with some improvements and extensions, are waiting until I can build a dedicated test / example website. That is actually my plan for today. [Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 07-12-2009 [eluser]Daniel H[/eluser] Sounds superb - will look forward to seeing it! [Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 07-13-2009 [eluser]mrtavo[/eluser] Hello every one, First of all, congratulations for this DMZ plugin, it's very impressive; and in second place, forgive my bad English. I've tried to do a simple relationship 1:N between 2 objects, let say, object A have 1 object B and object B have N relations with A. The point is that I'm using sqlite database. So, the configuration rules must be something like this: ObjectB: Code: class B extends DataMapper { Object A: Code: class A extends DataMapper { To try all this i have code a simple example: Code: function cr(){ This works fine with mysql, but not with sqlite. With sqlite i get this error: (i need to use sqlite, for some reasons) A Database Error Occurred Error Number: 1 SQL logic error or missing database SELECT As.* FROM (As) LEFT JOIN Bs as Bs ON Bs.id = As.B_id WHERE Bs.id = 10 I suppose it's something i have done wrong, but i don't know what i missed; because the same code (except table creation method) works with mysql. In fact, the relations are done, because in the sqlite tables they are well inserted, (I can see them using scaffolding), and give no errors. Any ideas? * sqlite database exists and if it doesn't, it's created with a pre_system hook. * sqlite tables exists, i have done some querys this db object. * sqlite relations exists, and it's possible to do standard querys to the db object and it gives the real (and well formed) result. (but not with LEFT JOIN) * it seems to be a sqlite syntax problem. (maybe) [Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 07-13-2009 [eluser]OverZealous[/eluser] Original comment removed, see below. [Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 07-13-2009 [eluser]OverZealous[/eluser] Man, I gotta stop writing before I wake up. See below. |