![]() |
DataMapper ORM v1.8.1 - 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 ORM v1.8.1 (/showthread.php?tid=42440) |
DataMapper ORM v1.8.1 - El Forum - 07-13-2011 [eluser]sqwk[/eluser] @Wan: That's actually also what I was getting at. Previously I would get the necessary rows from the parent table, foreach through them and get the ids in order to then only use one extra query for the child table. Another foreach loop would then puzzle the two together again. It would be nice if Datamapper could simplify this a little. DataMapper ORM v1.8.1 - El Forum - 07-13-2011 [eluser]WanWizard[/eluser] include_related() does exactly that, puzzle them together. It would lead to a repeat of all parent columns for every child record, just like you would get from a handcrafted join. DataMapper ORM v1.8.1 - El Forum - 07-13-2011 [eluser]Andy78[/eluser] @WanWizard Thanks that made sense. All that was required was a single line Code: //get user types [quote author="WanWizard" date="1310562244"]@Andy78, Code: $users->user_type->get(); doesn't do anything, as at that moment, the $users object is empty (you haven't done a get yet). Besides that, you can't do something like that. Relationships live in a three dimensional space, where as query results are two dimensional. If you want the result of a relationship in a single query, you have to flatten it using include_related(), which will include the fields of the related table in the SELECT using a JOIN. $user->user_type->get() will only get the user_type of the user currently present in the object, not of all retrieved objects.[/quote] DataMapper ORM v1.8.1 - El Forum - 07-13-2011 [eluser]Andy78[/eluser] Is there anyway to stop the Automated Timestamps updated function from working when a specific field is updated? This is because I have a last_login field in my users table and an updated field so when I update the last_login field it automatically updates the updated field which I don't want. Also I'm using $user->last_login = date('Y-m-d, G:i ![]() DataMapper ORM v1.8.1 - El Forum - 07-14-2011 [eluser]WanWizard[/eluser] Set the fieldname for the updated column to something else: Code: Class mymodel extends Datamapper { DataMapper ORM v1.8.1 - El Forum - 07-20-2011 [eluser]Unknown[/eluser] Hi, I have 2 questions 1. Code: $u = new User; transaction for both $u->profile->save() AND $u->save() is not rolling back, if validation fails on $u->save(). so what happens, i have $u->profile->save() actually saving, but $u->save() not saving. As far as I understand, from this example, if one of them fails, both of them should be rolled back. How would I make them both rollback if one of them fails? question #2. Code: $u = new User so $u->delete() will only delete user, but won't delete profile? is there a way of cascade-deleting all table entries dependent on $u??? DataMapper ORM v1.8.1 - El Forum - 07-21-2011 [eluser]WanWizard[/eluser] If you haven't enabled 'auto_transaction' in the config or in the model, Datamapper doesn't use any transactions. If you have, MySQL doesn't support nested transactions, so if you start a second one (which $u->save() does), the first one is committed automatically. The only way around it is to set 'auto_transation' to FALSE, en code your own begin and end of the transaction. Cascading delete is automatic and enabled by default. It only deletes related records if they are detected to be children. If the records contains a FK, it will consider the record to be the child. To avoid deleting the parent (and by cascading delete half your table), it will set the FK to null to delete only the relation. DataMapper ORM v1.8.1 - El Forum - 07-21-2011 [eluser]Arministrator[/eluser] Hi good people ![]() So far datamapper has really made my life easy, when it comes to databases, but now I have a task that seems to be a bit complicated, and I could use some help. Here's the database tables (with some sort of relation structure illustrated, actual join tables not shown) User |+Accounts |+Incomes |+Income categories |+Expenditures |+Expenditure categories My problem is how to access total expenditure by categories for all accounts. For example there's an expenditure category called 'Car' in Account 1, and a category called 'House' in Account 2. But Account to also has a Car category. So I want to add the sum up all Car expenditures in Account 1 and add it to the sum of Account 2 Car category. And since I don't know how many accounts a user has created, I have to be able to do this in some kind of a loop. Messy, I know. All suggestions welcome! (on database structure and relations too) EDIT: I think I'm halfway there, I'm able to get sums of categories for a single account. Maybe I'll combine and add the categories for multiple acconts using arrays. I'd still very much like to get your opinions on this one. EDIT: I think I'll just relate Expenditure categories to User. Then all be able to offer all categories for all acounts when entering a new expenditure, and will be able to easily sum it all up. However the structure I have now is simpler and more logical, but I just can't get it to work this way. Still any help would be appreciated. DataMapper ORM v1.8.1 - El Forum - 08-03-2011 [eluser]heldrida[/eluser] /** This was initially posted on the wrong thread (older version) and wanwizard already replyed back (see below) | I was actually seeing old documents, that didnt had this features! **/ Hi, for the following scheme: Code: ——————————————————————- - A product can have many Campaigns; My question is, I dont know how to get a product, that can be in many categories, in a specific campaign: - The product must be in catA or catB or catC or catD; - AND it must be of campaignX; Here’s some code http://pastie.org/2316484 I can do this by writting SQL, but I would like to understand how I can accomplish this trough Datamapper. Code: The lines 59 to 70 On $prod->where_related($cpgn)->get(), I’m getting a product that is campainX, that is not part of the selected category. Also, is there a way to see the query it generated ? What I do often is to place typos to get the error msgs with the query. From the last querys I saw, I guess I could solve this if I had the “AND_WHERE” or something :T Code: the following query works fine: Thanks a lot for looking! ------- this is wanwizard answer: You can dump the SQL by using $yourobject->check_last_query(). And I suspect you have an issue with where order here, as you correctly stated, the categories need to be within brackets. See http://datamapper.wanwizard.eu/pages/get.html#Query.Grouping on how to do that. And my I suggest you upgrade your Datamapper? v1.6.0 is ancient. And if you’re not using this version, you’re posting in the wrong thread. ------ I'll do some tests! and I'll edit DataMapper ORM v1.8.1 - El Forum - 08-03-2011 [eluser]Vheissu[/eluser] [quote author="WanWizard" date="1310485393"]@Colm Ward, Expect more misery now that the devs are very busy making the core inaccessable to third party solutions. I'm contemplating stopping with DM's support for 2.0.2+ and reactor at the moment, until they've sorted out their mess. And to quit if they don't...[/quote] Aww man, don't stop DataMapper support, I've just started heavily getting into this library and am about to release a large-scale auth library that uses DataMapper for everything. I agree about the devs though, they just seem to be breaking everything. Especially when they made a whole heap of variables protected that one time and it broke Modular Extensions amongst other third party libraries. |