DataMapper 1.6.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 1.6.0 (/showthread.php?tid=11358) Pages:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
DataMapper 1.6.0 - El Forum - 02-25-2009 [eluser]tdktank59[/eluser] Well first off its in a fully managed object. Im not exactly sure id wait until Overzealous or someone else can answer your question. In my opinion it just makes everything easier as far as relations, management, validation etc... To lets say check a username to see if its already taken You can do this from any controller throughout the CI site. (this is just a basic example but it shows what im talking about. Code: $u = new User(); Code: $u = new User(); Then in the User model Code: function check_username() DataMapper 1.6.0 - El Forum - 02-25-2009 [eluser]cupacup[/eluser] SOLVED!! The name of table was wrong. scopredmet_uporabniki is the right way, uporabniki_scopredmet wrong. Hello! I have following problem, when i want't to save relations(has_many) Code: Fatal error: Call to a member function num_rows() on a non-object in C:\projekti\iam\streznik\htdocs\system\application\libraries\datamapper.php on line 2560 Code: Object CI_DB_mysql_result extends CI_DB_result ( the code I'am using is Code: // Nov objekt Model Scopredmet Code: class Scopredmet extends DataMapper { Model Kategorije Code: class Kategorije extends DataMapper { Model Uporabniki Code: class Uporabniki extends DataMapper { CI is 1.7.1 and DM from OverZealous.com dated february 17. DataMapper 1.6.0 - El Forum - 02-25-2009 [eluser]tdktank59[/eluser] The way ive been able to do it is save the object first then save the relations... Only way ive gotten it to work... DataMapper 1.6.0 - El Forum - 02-25-2009 [eluser]OverZealous[/eluser] If you are saving multiple, new objects, you always have to save the objects first. Calling $obj1->save(array($obj2, $obj3)) will only save $obj1 to the database, and the relationships between $obj1 and $obj2, and $obj1 and $obj3. It has to be this way, or else DM would spend a lot of time checking to see if something needs to be saved to the database. Also, you can save relationships to non-complete objects this way: Code: $obj2->select('id')->get(); -- As for the previous discussion, about the multiple queries, it's how the field names are looked up. You'll only see the LIMIT 1 query once per model, as DataMapper has to determine which columns are available on the table. This is the standard ActiveRecord process. If your application needs so much speed that calling one, near-instantaneous query to look up the column names is too much, then you probably shouldn't be using PHP, much less an ORM library. DataMapper and other ORM libraries are designed to make developing code easier and faster. Most knowledgeable software developers will tell you that you should worry about application design and long-term management of code before you worry about fine-tuning for speed. DataMapper 1.6.0 - El Forum - 02-26-2009 [eluser]unsub[/eluser] just wanted to say, this is astonishing! fantastic stuff, really; it's inspiring for a novice like me to see something like this! cheers, and thank you so much DataMapper 1.6.0 - El Forum - 02-26-2009 [eluser]quasiperfect[/eluser] thanks @OverZealous.com for u'r response. i'm not worried about one query but i didn't understand why the query was run. like i said in my first post is my first encounter with datamapper and with orm in general. to be honest i only tested with 5-10 lines of code (busy with a project) that run queries one time per table so i didn't see it dose that only one time. i was worried that it uses extra queries for every interrogation. i will test better next time DataMapper 1.6.0 - El Forum - 02-26-2009 [eluser]OverZealous[/eluser] I completely understand! :cheese: Feel free to ask any other questions you might have. You'll find, once you get used to it, that DataMapper is incredibly powerful for what it is, and allows you to produce results surprisingly fast. It does have limitations, and you'll probably need to work around some of them, but several of use here are still helping to fine-tune it. DataMapper 1.6.0 - El Forum - 02-26-2009 [eluser]tdktank59[/eluser] So just so we can get a good example of how to save a uncomplete object with an object. Code: $d = New Dqip(); with your example above how would be the "other" way to do this. BTW above works. DataMapper 1.6.0 - El Forum - 02-26-2009 [eluser]tdktank59[/eluser] edited: ignore this post... DataMapper 1.6.0 - El Forum - 02-26-2009 [eluser]OverZealous[/eluser] In your example, just add ->select('id') in to your reference lookups. What I mean by "incomplete" objects is that you don't bother selecting the whole row. You will still be able to save the relationship, as long as the object has the correct ID. I'm not sure why you would be seeing validation errors. What fields exactly? I don't think I changed the validation fields any. Are you sure that 'required' isn't getting set on these fields? Are you setting 'required' on the relationships? |