![]() |
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 - 05-05-2009 [eluser]wolffc[/eluser] I see, thanks for the help. DataMapper 1.6.0 - El Forum - 05-08-2009 [eluser]bibstha[/eluser] Stuck with database design to satisfy the Datamapper's structure. What I have is events table and users table events ---------- id name users_ ---------- id username password ... Now a User can be related with an event but the relation can be of several type. Say the relationship between user and event can be invited, confirmed, participated, ... So i have the table events_users events_users ------------ id event_id user_id participation_type (ENUM with invited, confirmed, participated) Now I cannot seem to find a way to populate participation_type field, coz both events_id and user_id are automatically filled by DM. Also, is there any way to restructure the Database? Thanks DataMapper 1.6.0 - El Forum - 05-08-2009 [eluser]bibstha[/eluser] Oh I guess DMZ will be able to handle that.. I am taking a look at this. But if DM cannot by default handle it, isn't that a serious limitation? DataMapper 1.6.0 - El Forum - 05-08-2009 [eluser]OverZealous[/eluser] @bibstha I don't think it is that big of a limitation. You can always come up with different ways to relate information. In the past, I created a dedicated model to handle complex joins. Honestly, the inability to relate the exact same two objects more than once was a bigger limitation. Anyway, that's why I continued development on DataMapper as DMZ ;-) ? stensi has not been able to work on it in a while. (Also, in case it isn't obvious, DMZ still does not offer a way to relate the same object multiple times where the primary key would be on [event_id, user_id, participation_type]. Meaning, unless you relate them using different related_fields, each User can only be related once per Event. But I believe you aren't expecting that, here!) DataMapper 1.6.0 - El Forum - 05-08-2009 [eluser]camporter1[/eluser] Hello again. I know that it's possible to get all of my user's associates, but how might I go about doing the reverse, and figuring out which other users have a specific user as an associate? My model and stuff is back on page 83. Code: $user->associate->get(); I was thinking I could do the following: Code: $user = new User(); ![]() Thanks. DataMapper 1.6.0 - El Forum - 05-08-2009 [eluser]OverZealous[/eluser] It's just Code: // this is the user Think of the relationship like this: Code: .-----------. 1 N .-----------. Where User and Associate just happen to be the same class. DataMapper 1.6.0 - El Forum - 05-08-2009 [eluser]camporter1[/eluser] What is $as_id if I don't know what associate I'm initially looking for? Basically all I know is that I have the main user's id (e.g. 2). I want all other user's associates and if I find that the main user's id is an associate for one of them, then I want to return that user that has them as an associate. It is similar to a friends relationship, where a person can have someone as a friend, but not until the other person adds them as an friend as well will the application think that they are mutual friends (if that makes any sense). Maybe this database configuration is wrong? It seemed to work (albeit less gracefully) when I was using just queries, but obviously it was more messy. DataMapper 1.6.0 - El Forum - 05-08-2009 [eluser]OverZealous[/eluser] Let's use the friends as an example - it's easier to understand: Code: // This user's friends Replace 'friend' with 'associate' as needed. Apply only as directed. Side effects may include awesomeness, rock-star code monkey status, and utter lack of SQL code. DataMapper 1.6.0 - El Forum - 05-08-2009 [eluser]camporter1[/eluser] OK, but I'm trying to check if there are essentially what social websites like to call 'unconfirmed' friends. (Not that the other code wasn't unnecessary, it was actually incredibly useful as well. Instead of limiting it to only the associates that the user has, I did this to check all associates: Code: $user = new User(); Thanks once again. It feels good to take the DM drugs ![]() DataMapper 1.6.0 - El Forum - 05-08-2009 [eluser]OverZealous[/eluser] Try this: Code: // all two-way associates If that works, that's only 2 queries, much more efficient. |