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 - 11-04-2008 [eluser]OverZealous[/eluser] @ Paul Can you give an example, please? DataMapper 1.6.0 - El Forum - 11-04-2008 [eluser]Paul Apostol[/eluser] It's about Star schema. I have 3 tables which must be connected like there. I don't know how to make this work in DM style DataMapper 1.6.0 - El Forum - 11-04-2008 [eluser]OverZealous[/eluser] Well, I don't know anything about star schema. If you gave a more specific example, I might be able to help better. You have a few choices. 1: You might not be able to use DM in this topology. It probably isn't the right tool for data warehousing. 2: Use a model as your "join" table. Then you have to edit DM (or create a data mapper extension - please look back through this forum) to allow multiple joins. 3: Skip around DM for your multi-way joins. 4: Re-think your design. Does it actually <i>need</i> multiple joins? Many times the database design is overly complicated when multiple joins are being used regularly. Again, without specific examples, I'm shooting from the hip. DataMapper 1.6.0 - El Forum - 11-04-2008 [eluser]Paul Apostol[/eluser] Let's see why I need this joining table (just another example): 1. I have users (user1, user2) 2. I have books (book1, book2) 3. I have actions to the books (preview, download) The relations are many to many. Every user have a set of actions on every book. So, "user1" can have only the right to do "preview" and only for "book2" On the page I'll display the list of the books (in our case only "book2") and the user can do only "preview". The easy part is that in DM style I can easily retrieve the list of books. But how can I retrieve the list of actions related to that book for that user? Thanks a lot for your fast answers. PS: yes, it's an idea to skip DM for this particular case. DataMapper 1.6.0 - El Forum - 11-04-2008 [eluser]OverZealous[/eluser] Well, option 2 would work in that example. It's not the prettiest, but it solves the problem: Users have many Bookrules Books have many Bookrules Actions have many Bookrules Bookrules has one Book Bookrules has one User Bookrules has one Action Your model tables would be: users, books, actions, bookrules Your relationship tables would be actions_bookrules bookrules_books bookrules_users You could then get the books through Code: $user->bookrules->get(); Update: I forgot to mention that this will generate a lot of queries on the server. You might be able to reduce them using some of the above mentioned additions to DM. DataMapper 1.6.0 - El Forum - 11-04-2008 [eluser]Paul Apostol[/eluser] thanks again. I'll give it a try DataMapper 1.6.0 - El Forum - 11-05-2008 [eluser]bojack[/eluser] I am looking to implement an automatic relationship for any new record from one model to another. IE: any new 'permission' is automatically related to the 'root' role. I have tried something like this: Code: public function save($object = '') { Using this function not only is the new relationship not saved, the new record itself is not created. Any tips about what I am missing (probably something obvious). DataMapper 1.6.0 - El Forum - 11-05-2008 [eluser]OverZealous[/eluser] First, if you pass an object into save() it will only save a relationship. So, you didn't actually save the object at all. Second, you need to save $this first. Code: public function save($object = '') { DataMapper 1.6.0 - El Forum - 11-05-2008 [eluser]___seb[/eluser] hi, I'm new to dattamapper and orm. I have prob trying to get the tags of the links that have one specified tag. I mean : Tag xxx -> links with that tag -> all tags of each link. Code: $tag = new tag(); No tags are found in the second foreach. ( The table tags has a field 'tag' (the name/string) ) any idea ? (i tried some things without success) DataMapper 1.6.0 - El Forum - 11-05-2008 [eluser]OverZealous[/eluser] What you are doing wrong is not selecting the ID field. In fact, you probably don't need the ->select() at all. By not selecting the id field, DM cannot look up the relationships, since it doesn't know the ID of the bookmark. Try this: Code: $tag = new tag(); If you need to select, make sure you select the 'id' field as well. |