![]() |
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 - 06-26-2009 [eluser]OverZealous[/eluser] It would be just awesome to simply receive a postcard. I have a P.O. box listed on my website. ![]() I could start a collection of postcards where people are using DMZ. That would be really fun! I've got a blank corkboard in front of me... DataMapper 1.6.0 - El Forum - 06-26-2009 [eluser]PoetaWD[/eluser] [quote author="OverZealous.com" date="1246014688"]It would be just awesome to simply receive a postcard. I have a P.O. box listed on my website. ![]() I could start a collection of postcards where people are using DMZ. That would be really fun! I've got a blank corkboard in front of me...[/quote] I sure will send you a nice card ! ![]() DataMapper 1.6.0 - El Forum - 06-27-2009 [eluser]PoetaWD[/eluser] Hey man... Bought you Post Card today.. I will send it monday... hehe I have a question... it is regarding relationships. In this case I have the objects Sale that has relationship with Type_of_sale and 2 profiles, one represents the Client and the other represent the Salesman. The problem is that there are no fields in the profile that would point that the profile is from a Client or a Salesman. That would be pointed by the object related to the profile called User ! The Profile object only has the details of the user the role is in the User object. Here is my controller: Code: $obj = new Sale(); Would be best to include a field in the profile object to point if it is a Client or a Salesman ? Thanks in advance DataMapper 1.6.0 - El Forum - 06-28-2009 [eluser]OverZealous[/eluser] It's easier than you imagine, if you are using advanced relationships from DMZ! Code: $obj->include_related('client', array('stName')); Which are now accessible using $obj->client_stName and $obj->salesman_stName. This requires your models to look something like this (excuse any mistakes, I'm doing this from memory): Code: class Sale extends DataMapper { Sales Table: Code: id | ... | salesman_id | client_id Usage in controller Code: $sale = new Sale(); Now, you could rename these in a whole variety of ways. The key is that you cannot have the same 'related_field' (ie: 'clientsale') for two different relationships, and that you have to declare both sides of the relationship. DataMapper 1.6.0 - El Forum - 06-29-2009 [eluser]PoetaWD[/eluser] @DMZ Man... took me about 3 hours reading the documentation and your post to figure this out... It FRIED my brain tottaly ! I cant imagine how you did this... but... you did... and for that I take my hat off for you... really... you are great ! I hope one day I can do stuff like that... But getting back to the program... ![]() Again, I am building a table with the data from Sales... The fields I am having trouble with are Salesman (I named Staff) and Client. I will post the whole code cause it can be a example for other people there are learning... Here are my models: Profile.php Code: <?php Sale.php Code: <?php They do work... Here is my controlle : Code: $obj = new Sale(); The first question: How do I save the relationship ? Code: $obj->cliente_id = $this->input->post('client'); The second question: In my view i´m doing a loop like this: Code: foreach ($objects as $list) But something is wrong because it gives me the staff name the same as the client name... the ID is being given right. Code: <td>18</td><td>Passagem Aerea</td><td>8 - jk costa de mello paiva</td><td>6 - jk</td></tr> and when I remove the line: Code: //$obj->include_related('client', array('id','stName','stLastname')); It will show the name of the staff... Code: <tr> Very weird... Maybe I am doing something wrong... maybe is a BUG... I dont know... I hope you can help me.. Thanks DataMapper 1.6.0 - El Forum - 06-29-2009 [eluser]OverZealous[/eluser] @Poetawd For saving, see Save an Advanced Relationship (scroll down), but the basic idea is this: Code: // save one advanced relationship Code: $sale->save(array( As for your second issue, it looks like you might have a typo, because your ids are coming off 'list', but your names are coming off 'lista'. If this is just a copy/translation error, check this to see if we can track down the problem: Code: $list->client->get(); Code: 1 - John Smith [1 - John Smith] If the information is different, like this: Code: 1 John Smith [1 - John Smith] DataMapper 1.6.0 - El Forum - 06-29-2009 [eluser]PoetaWD[/eluser] Man you are fast... ![]() It is a translation error... the code is in portuguese... sorry, here is the original: Code: foreach ($objetos as $lista) I added the query screenshot as a image... I took it from the $this->output->enable_profiler(TRUE); Please take a look... Thanks DataMapper 1.6.0 - El Forum - 06-29-2009 [eluser]PoetaWD[/eluser] sorry it is in portuguese... DataMapper 1.6.0 - El Forum - 06-29-2009 [eluser]PoetaWD[/eluser] that was with the line commented... Here is the right one: Code: SELECT `vendas`.*, `tiposvendas`.`stNome` AS tiposvenda_stNome, `profiles`.`stNome` AS cliente_stNome, `profiles`.`stSobrenome` AS cliente_stSobrenome, `profiles`.`stNome` AS funcionario_stNome venda = sale stNome = stName funcionario = staff stSobrenome = stLastname DataMapper 1.6.0 - El Forum - 06-29-2009 [eluser]OverZealous[/eluser] I'm pretty sure it's a bug in DMZ. I'm doing some tests now, to see what's going on. It might take me a few minutes. Update: Yes, it is a bug. I've got a fix in place, and will have an updated version of DMZ for download in about 10 minutes. Thanks for finding this PoetaWD - it's a very serious bug, but luckily had an easy fix! |