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 - 03-02-2009 [eluser]stefanv[/eluser] [quote author="OverZealous.com" date="1236006441"] Any thoughts?[/quote] Perhaps the code: Code: // Build up the error message should be replaced with: Code: // Build up the error message But then the error string is going the be real long... Some intelligence should be added, since the 'fieldname' isn't needed for all the messages added. So: Code: Username is a required field. Code: Username is a required field and should be at least 3 character long DataMapper 1.6.0 - El Forum - 03-02-2009 [eluser]OverZealous[/eluser] I just don't see a good reason to return multiple errors per field. Once one error occurs, that should be all that is really needed to convey the message. Since the order you set the validation rules matters, if you put 'required' at the end, the required rule wouldn't ever run until after the min_length rule, therefore you'd always get: Code: "Username must be at least 3 characters long." Which not only conveys all of the information, but makes more sense. Also, there is no practical way DataMapper could combine error messages and still be language-agnostic. I still say, if you need that kind of compiled information ("Field should be this and that and this too."), either create a custom validation method and error message, or provide that information inline. Anyway, this is probably something for stensi or someone else to decide. It's easy enough to customize if that is what is desired. DataMapper 1.6.0 - El Forum - 03-02-2009 [eluser]stefanv[/eluser] [quote author="OverZealous.com" date="1236011250"]I just don't see a good reason to return multiple errors per field. Once one error occurs, that should be all that is really needed to convey the message. Since the order you set the validation rules matters, if you put 'required' at the end, the required rule wouldn't ever run until after the min_length rule, therefore you'd always get: [/quote] Looking at your reply and (re)thinking what I stated.. You are probably right. There should only be 1 error per field: the must important one (the first one in the validation rule) The statement 'the validation rules order' triggered me to look at my code again.. The order was wrong.. fixed it.. This fix solved my problem. 1 thing i would like to add.. ->string and ->all both represent all the errors found.. Wouldn't it be nice to add something like ->current the get a list of the current errors (the limited list) DataMapper 1.6.0 - El Forum - 03-02-2009 [eluser]OverZealous[/eluser] [quote author="stefanv" date="1236012299"] 1 thing i would like to add.. ->string and ->all both represent all the errors found.. Wouldn't it be nice to add something like ->current the get a list of the current errors (the limited list)[/quote] I'm confused by this. From the guide: Code: $obj->error->all; // all errors from last validation as an array What else do you want? The errors listed are all of the errors for this transaction. If you see an error in this list, it happened now. There is one minor known bug, that $obj->error->transaction doesn't get initially set or cleared. This only occurs if you are using auto transactions, AND you get a transaction error. DataMapper 1.6.0 - El Forum - 03-02-2009 [eluser]Matthew Pennell[/eluser] Someone might have already pointed this out, but just in case - the download links on the DataMapper User Guide are broken. DataMapper 1.6.0 - El Forum - 03-02-2009 [eluser]Billy Khan[/eluser] Yep, really would like to try this but the download links are broken. DataMapper 1.6.0 - El Forum - 03-02-2009 [eluser]OverZealous[/eluser] Check the first page of this thread. The latest official version of DataMapper is there, including the help documentation. You do not need to download it from stensi's website. DataMapper 1.6.0 - El Forum - 03-03-2009 [eluser]tdktank59[/eluser] I came up with a neat function for deleting single or multiple relationships while editing a record. For instance, Brainstorm -> id -> name -> description -> author_id -> data_source_1_id -> data_source_2_id DS1 and DS2 cannot be the same and can both be nulled if only 1 source is provided. However while updating I dont belive you can delete then save... (not sure here and havnt tried...) But this will search the master object, grab the id of the field you want to delete, create the object of the relation and delete it all for you! Anyways heres the fun little method I created (just tacked it into the brainstorm model Sorry for the somewhat confusing nature of the variables lol Code: /** Then in the controller to delete the records set an array such as (you need the same format) the $array[] makes it so you can have multiples of the same (so I could delete DS1 and DS2 at the same time) You can fill this in with a value it wont matter... just as long as the array under it has the $class => $field Code: $delete[] = array ($class => $field); and then right before you save call the delete method as such Code: // Delete any nulled relations Simple as that let me know if there are any questions. BTW I tested and this method works. DataMapper 1.6.0 - El Forum - 03-03-2009 [eluser]OverZealous[/eluser] I'm confused as to what this method does. It seems like a lot of complexity, but all it does is delete a set of related objects? Why would you use this instead of: Code: $master->delete(array( Or, if you know you are using the has_one fields on the same table: Code: $master->data_source_1_id = NULL; I'm just not sure what the method does. Also, you query $mast_obj in a way that might return multiple values, however, you only call $mast_obj->delete() on the first returned value, possibly leading to unexpected results. Finally, if you just want a simpler method to delete a set of related objects, why not this: Code: function delete_related_fields($fields) { Usage: Code: $my_obj->delete_related_fields(array('data_source_1', 'data_source_2')); This also allows for deleting all related has_many ones. --- On a related note, I'm trying to get my project to a private beta by this weekend. If everything goes as planned, I hope to set some time aside to build up some examples and better document my extended DataMapper. DataMapper 1.6.0 - El Forum - 03-06-2009 [eluser]Billy Khan[/eluser] I am new to datamapper and need to do this... I have three tables, regions, members and join_members_regions. After i have downloaded all data into a csv, i need to truncate the members and join_members_regions tables. From reading the help pages, i know i can do delete_all or delete but this requires a specific member record, ho do i delete all from both? |