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-18-2009 [eluser]DavidZB[/eluser] Hi! Well, I've tried to read all of the post just to find an answer... but there are 56 pages!!. I couldn't find the answer, so here it goes: I'm making a Bug Tracker module for a CI app... I'm using DataMapper. I have my "bugs" table and my "priorities" table. The idea is that a bug can be updated whenever I want, just changing the priority, but, of course, keeping track of the priorities it had all along. There is, of course, the bugs_priorities table. there's an id, bug_id and priority_id.... but I need to add a date field, so I can know when happened that update.... bugs - id - name - details priorities - id - name (i.e: Normal, Critical, Trivial...). bugs_priorities - id - bug_id - priority_id - date <- Here is my problem I need to know, in example, the priorities that a bug had between two dates... How can I do that? is there another way? Thanks... PD: Sorry about my english! DataMapper 1.6.0 - El Forum - 02-19-2009 [eluser]OverZealous[/eluser] @DavidZB There is no way to get information from the join tables in DataMapper, currently. You need to use a third Object to store the information, like this: bugs, priorities stay the same. prioritydates fields: id, date has_one: priority, bug bugs_prioritydates id, bug_id, prioritydate_id priorities_prioritydates id, priority_id, prioritydate_id Code: $bug = ... Now, in the current implementation, you have to use the extra join tables, which is rather ugly, and makes certain complex queries difficult. I have been working on a version that (among other things) allows has_ones to use traditional, in-table fields. You can try it out a few pages back, it is almost a drop-in replacement for the official version. If you use that, then you can drop the join tables, and just make your prioritydate table: id, date, priority_id, bug_id And with the testing version, you can run a query like this: Code: $bug = ... The testing code is definitely experimental, however, so you might not want to use it in a production system yet. DataMapper 1.6.0 - El Forum - 02-19-2009 [eluser]macigniter[/eluser] [quote author="Murodese" date="1233341217"] Code: class Creator extends DataMapper And join tables would become join_files_users and join_files_creators.[/quote] I am just now implementing this and it is not working for me I get the following error: Code: Error Number: 1054 Why doesn't it use 'join_files_creators'? This is my query: Code: $c = new Creator(); DataMapper 1.6.0 - El Forum - 02-19-2009 [eluser]tdktank59[/eluser] Check your mysql driver In the manual go to troubleshooting and should be the first thin there DataMapper 1.6.0 - El Forum - 02-19-2009 [eluser]macigniter[/eluser] I already did... that's not it DataMapper 1.6.0 - El Forum - 02-19-2009 [eluser]tdktank59[/eluser] I figured it out lol Because the table in the Creator model is set to users so it will join a users table not the creator table... Change $table = "creator"; and it should join the right table that you want. DataMapper 1.6.0 - El Forum - 02-19-2009 [eluser]macigniter[/eluser] Actually there is no "creators" table. The situation is as follows: There's a "users" table and a "files" table. When a new file is added via the admin panel both the "creator" (which is a user) and the relation of the file to the users (managing rights) is stored. So I need to save a relation to: 1. the user who created the file 2. the users who are eligible to view the file DataMapper 1.6.0 - El Forum - 02-19-2009 [eluser]tdktank59[/eluser] ok then... creator then has to extend users instead of datamapper Check this page it might solve your problem http://stensi.com/datamapper/pages/relationtypes.html This is a self referencing type issue. DataMapper 1.6.0 - El Forum - 02-19-2009 [eluser]macigniter[/eluser] I read that, too. Tried exactly what was explained, but just can't get it to work Can anyone help with a code example? EDIT: I am also not so sure if this is a self-referencing issue. Since I really want to reference Users <> Files and Users (as Creator) <> Files. I just can't use the join_files_users table twice... It's not that a User has_one or has_many Creators. A file has both a relation to users and a creator. I'm lost DataMapper 1.6.0 - El Forum - 02-19-2009 [eluser]macigniter[/eluser] Maybe the only solution to this is adding another CREATORS table? USERS id ... FILES id ... CREATORS id join_files_users join_creators_files join_creators_users It's kind of redundant since creators are in fact users, but I have no clue how to solve it otherwise... |