DataMapper ORM v1.8.0 - 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: DataMapper ORM v1.8.0 (/showthread.php?tid=37531) |
DataMapper ORM v1.8.0 - El Forum - 02-14-2012 [eluser]WanWizard[/eluser] That should work without problem, providing there is an entry in the $has_one or $has_many arrays in the User model called 'products' (and you should define it in User, because that's where you want the relation to be checked). DataMapper ORM v1.8.0 - El Forum - 02-14-2012 [eluser]ricardocasares[/eluser] Well, it is not working, I don't know where am I wrong. My user model Code: class User extends DataMapper { Product model Code: class Product extends DataMapper { The controller Code: class Test extends CI_Controller { Ok this code always returns 1, and creates the records in DB, no matter the validation constraint to 3 products per user limit. I'm using DM 1.8.2, and CI 2.1.0, any ideas? DataMapper ORM v1.8.0 - El Forum - 02-15-2012 [eluser]drakeonfire[/eluser] Hello ricardocasares, I'm no expert, far from it, but with reference to this: Code: class User extends DataMapper { Also when you refer to 'products' I think you need to refer to it as it's singular name (lowercase model name), so it would need to be 'product' - Again I may be wrong but hopefully it's worth a try :-). Amended version: Code: class User extends DataMapper { DataMapper ORM v1.8.0 - El Forum - 02-15-2012 [eluser]ricardocasares[/eluser] Drake you are right, It's validation, but it's ok in my models, I just mess up here while writing the post. These are the actual files in my project: Code: class User extends DataMapper { Code: class Product extends DataMapper { DataMapper ORM v1.8.0 - El Forum - 02-15-2012 [eluser]ricardocasares[/eluser] Can't make it work, maybe it is the way I'm saving the objects? Code: function test() DataMapper ORM v1.8.0 - El Forum - 02-23-2012 [eluser]ricardocasares[/eluser] Well I'm getting this error now: Code: A Database Error Occurred This happens while trying to do this: Code: $u = new User(); Pleaaaseee, what I'm I doing wrong?? DataMapper ORM v1.8.0 - El Forum - 02-24-2012 [eluser]ricardocasares[/eluser] Ok, I got it all working now... Except, I need to do the following: Code: var $validation = array( The $products_limit comes from the "plan" the user has associated, and it's stored in the session when the user logs in. When I try to run this I get: Code: Parse error: syntax error, unexpected T_VARIABLE in /var/www/stocker/application/models/user.php on line 11 Is there any way to make this setting dynamic? DataMapper ORM v1.8.0 - El Forum - 02-24-2012 [eluser]WanWizard[/eluser] You can not put any code in a property assignment. So you have to do that in your constructor, before you call the parent: Code: $this->validation['product']['rules']['max_size'] = $products_limit; DataMapper ORM v1.8.0 - El Forum - 03-12-2012 [eluser]DerLola[/eluser] Hi people, I've been using CI for quite a while but I'm new to ORMs, so please be.. gentle I have a timelines table and an events table. Every event has a timelines_id foreign key. Now I want to retrieve a timeline and its event, here's my simplified code Code: class Timeline extends DataMapper { Code: class Events extends DataMapper { And in the controller I say: Code: $timeline = new Timeline($id); Now how do I convert the result into a simple object (not the ORM object)? I need to use it in my template engine. I've looked at the to_array extension but that doesn't seem to do it. I want a timeline object containing a regular array filled with event objects. Any help is much appreciated! DataMapper ORM v1.8.0 - El Forum - 03-13-2012 [eluser]WanWizard[/eluser] Datamapper doesn't work with "regular" objects, it works with Datamapper objects. There is also a one-to-one relation between a record and an object, it's how the design pattern behind Datamapper works, so data from one table will never be in the object of another. If you want a custom data structure, you can create an extension for it (similar to the array extension). |