DMZ 1.7.1 (DataMapper OverZealous Edition) |
[eluser]WanWizard[/eluser]
I've updated this text to clarify this, and added a link to the save() method.
[eluser]modano[/eluser]
Deleting record error: When running the delete() function on an object, it doesnt seem to be able to delete the relationships. According to the manual, the delete function has built in house cleaning. The record Im trying to delete does exist, and has multiple relationships with one other table. Here is the error message Im getting: ======================== A Database Error Occurred Error Number: 1451 Cannot delete or update a parent row: a foreign key constraint fails (`db01/posts_tags`, CONSTRAINT `Ref_21` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION) DELETE FROM `posts` WHERE `id` = 3 ========================= Grateful for any help on this!
[eluser]WanWizard[/eluser]
Yes, it does. But currently it can't work if you have defined foreign key constrains on the tables. This is because it deletes the parent first, before it processes any relations. Can you add a ticket for this issue at http://bitbucket.org/wanwizard/datamapper/issues, so I won't forget to have a look at it? If possible, attach an sql file with the create commands for your posts_tags and related tables, including all constraint definitions, so I have something to test with.
[eluser]modano[/eluser]
gotcha. i didnt intentionally add the constrains, my database designer software did. so if i just remove it from the database modeling, it should work?
[eluser]WanWizard[/eluser]
In the meantime, I've been looking at the code. What you can try: at the top of the delete() function, there are these two lines: Code: $this->db->where('id', $this->id); Move these two lines down, just before this: Code: // Complete auto transaction As far as I can see, this makes sure all relations are deleted first, before the record itself is deleted. From a logic point of view a better solution imho. Could you try and see if this fixes your problem? If so you can leave the constraints in place.
[eluser]modano[/eluser]
thanks, that will most likely do it. will have to look into it tomorrow or monday, as im leaving the office now! have a good weekend, and thanks again!
[eluser]theprodigy[/eluser]
a quick update to my issue (the decrypt get_rules thing): I was able to get it to work, but I had to move the setting of my decryption key outside the constructor. For some reason, either the constructor is not being run (which I HIGHLY doubt), or maybe the object attributes are being over-written or something. I noticed that when I was getting the CI instance, and trying to load the encrypt library in the constructor, then using it in the encrypt and decrypt functions. I kept getting an error of trying to call a function on a non-object. When I moved it all down into the functions, it worked just fine. The same thing happens with the decrypt key. I am now setting it when instantiating it instead of in the constructor, and it all works just fine. Visual Aid time. this works Code: class User extends DataMapper { this DOES NOT work: Code: class User extends DataMapper { Can you think of any reason it wouldn't work the other way?
[eluser]theprodigy[/eluser]
Heh, ok, 1 more update. I just tried setting the variables in the constructor, but BEFORE calling the parent constructor, and it all worked just fine. So, I guess, evidentally, when I was setting them (after calling parent), it was silently failing validation or something. But if you set them BEFORE calling parent, and not change them after, it works just fine. VISUAL AID: Works: Code: function __construct($id = NULL) Does NOT Work: Code: function __construct($id = NULL)
[eluser]WanWizard[/eluser]
Ok, so your conclusion is that the Datamapper class constructor somehow interferes with your class property? I'll have to look into that, maybe the __get() magic method is doing something funny here...
[eluser]theprodigy[/eluser]
Quote:Ok, so your conclusion is that the Datamapper class constructor somehow interferes with your class property?Makes it sound kinda harsh. Wasn't meaning it that way, if that's how I sounded. :-P |
Welcome Guest, Not a member yet? Register Sign In |