Re: Model association problem - not getting expected array using $hasMany and $belongsTo association
Everything appears to be correct. Try deleting any files in app/tmp/cache/models/ if you haven't already. And set debug to 2, both so the models won't be cached and so you can see what queries are being run. On Mon, Oct 11, 2010 at 2:04 PM, Ashwani Kumar ashwani.mail...@gmail.com wrote: Hi all! Today was trying to learn associations but i couldn't succeed. I'm getting some issue in getting associated array. I've two tables : authors - id - name - email - website books - id - isbn - title - description - author_id controllers/authors_controller.php ?php class AuthorsController extends AppController { var $name = 'Authors'; function index() { $this-Author-recursive = 1; $authors = $this-Author-find('all'); $this-set('authors', $authors); } } controllers/books_controllers.php ?php class BooksController extends AppController { var $name = 'Books'; function index() { $this-Book-recursive = 1; $books = $this-Book-find('all'); $this-set('books', $books); } } models/authors.php ?php class Author extends AppModel { var $name = 'Author'; var $hasMany = array('Book'); } models/books.php ?php class Book extends AppModel { var $name = 'Book'; var $belongsTo = array('Author'); } books id isbn title description author_id 1 12345 book1 asdfasdfasdf 1 2 book2 asdfasfasdf ag as sadfas dfsdaf 1 3 345345 dfgvsdf gsdgsdf sdfg sdfg dfg 2 authors id name email website 1 Sams Publication s...@samspublications.com http://www.samspublications.com 2 Test Author auth...@testauthors.com http://www.author1.com When i try to run print 'pre'; print_r($authors), i get following array : Array ( [0] = Array ( [Author] = Array ( [id] = 1 [name] = Sams Publication [email] = s...@samspublications.com [website] = http://www.samspublications.com ) ) [1] = Array ( [Author] = Array ( [id] = 2 [name] = Test Author [email] = auth...@testauthors.com [website] = http://www.author1.com ) ) ) So, my problem is that there's no Book array in above array. Please help... Thanks in advance. Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Model association problem - not getting expected array using $hasMany and $belongsTo association
Hi all! Today was trying to learn associations but i couldn't succeed. I'm getting some issue in getting associated array. I've two tables : authors - id - name - email - website books - id - isbn - title - description - author_id controllers/authors_controller.php ?php class AuthorsController extends AppController { var $name = 'Authors'; function index() { $this-Author-recursive = 1; $authors = $this-Author-find('all'); $this-set('authors', $authors); } } controllers/books_controllers.php ?php class BooksController extends AppController { var $name = 'Books'; function index() { $this-Book-recursive = 1; $books = $this-Book-find('all'); $this-set('books', $books); } } models/authors.php ?php class Author extends AppModel { var $name = 'Author'; var $hasMany = array('Book'); } models/books.php ?php class Book extends AppModel { var $name = 'Book'; var $belongsTo = array('Author'); } books id isbntitle description author_id 1 12345 book1 asdfasdfasdf1 2 book2 asdfasfasdf ag as sadfas dfsdaf 1 3 345345 dfgvsdf gsdgsdf sdfg sdfg dfg 2 authors id nameemail website 1 Sams Publications...@samspublications.com http://www.samspublications.com 2 Test Author auth...@testauthors.com http://www.author1.com When i try to run print 'pre'; print_r($authors), i get following array : Array ( [0] = Array ( [Author] = Array ( [id] = 1 [name] = Sams Publication [email] = s...@samspublications.com [website] = http://www.samspublications.com ) ) [1] = Array ( [Author] = Array ( [id] = 2 [name] = Test Author [email] = auth...@testauthors.com [website] = http://www.author1.com ) ) ) So, my problem is that there's no Book array in above array. Please help... Thanks in advance. Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Association problem
Thanks for the help. I kept playing around with it and I realized I made the associations more complicated than I needed to. I removed the join tables (menu_item_types, menu_item_subtypes) and added the association: menu_item belongsTo(menu_type, menu_subtype). Doing a find('all') on MenuItem gets me all the info I need. On Nov 29, 12:42 pm, Dave davidcr...@gmail.com wrote: Try setting $this-recursive = 2. On Sun, Nov 29, 2009 at 5:04 AM, un professional iamunprofessio...@gmail.com wrote: I am trying to make some associations with a restaurant menu. I have five tables and they are all linked, although not directly. How do get info from all tables if some tables aren't in direct relation to the calling table? Here is my setup: menu_items -id -name -price menu_types: ( has only Lunch Dinner) -id -name menu_item_types (associates each menu item with either lunch or dinner) -menu_item_id -menu_item_type_id menu_subtypes: ( has Appetizers, Soups, Pasta, etc...) -id -name menu_item_types (associates each menu item with either Appetizers, Soups, Pasta, etc...) -menu_item_id -menu_item_type_id Basically, I want to be able to select all the info from all tables. The associations I have now are: MenuItem hasOne (MenuItemType, MenuItemSubtype) MenuType hasOne (MenuItemType) MenuItemType belongsTo (MenuItem, MenuType) MenuSubtype hasOne (MenuItemSubtype) MenuItemSubtype belongsTo (MenuItem, MenuSubtype) From MenuItemsController, I have no problem getting MenuItem, MenuItemType, and MenuItemSubtype but I can't get MenuType or MenuSubtype. How do I get those? Check out the new CakePHP Questions sitehttp://cakeqs.organd help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.comcake-php%2bunsubscr...@googlegroups.comFor more options, visit this group at http://groups.google.com/group/cake-php?hl=en Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Association problem
I am trying to make some associations with a restaurant menu. I have five tables and they are all linked, although not directly. How do get info from all tables if some tables aren't in direct relation to the calling table? Here is my setup: menu_items -id -name -price menu_types: ( has only Lunch Dinner) -id -name menu_item_types (associates each menu item with either lunch or dinner) -menu_item_id -menu_item_type_id menu_subtypes: ( has Appetizers, Soups, Pasta, etc...) -id -name menu_item_types (associates each menu item with either Appetizers, Soups, Pasta, etc...) -menu_item_id -menu_item_type_id Basically, I want to be able to select all the info from all tables. The associations I have now are: MenuItem hasOne (MenuItemType, MenuItemSubtype) MenuType hasOne (MenuItemType) MenuItemType belongsTo (MenuItem, MenuType) MenuSubtype hasOne (MenuItemSubtype) MenuItemSubtype belongsTo (MenuItem, MenuSubtype) From MenuItemsController, I have no problem getting MenuItem, MenuItemType, and MenuItemSubtype but I can't get MenuType or MenuSubtype. How do I get those? Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Association problem
Try setting $this-recursive = 2. On Sun, Nov 29, 2009 at 5:04 AM, un professional iamunprofessio...@gmail.com wrote: I am trying to make some associations with a restaurant menu. I have five tables and they are all linked, although not directly. How do get info from all tables if some tables aren't in direct relation to the calling table? Here is my setup: menu_items -id -name -price menu_types: ( has only Lunch Dinner) -id -name menu_item_types (associates each menu item with either lunch or dinner) -menu_item_id -menu_item_type_id menu_subtypes: ( has Appetizers, Soups, Pasta, etc...) -id -name menu_item_types (associates each menu item with either Appetizers, Soups, Pasta, etc...) -menu_item_id -menu_item_type_id Basically, I want to be able to select all the info from all tables. The associations I have now are: MenuItem hasOne (MenuItemType, MenuItemSubtype) MenuType hasOne (MenuItemType) MenuItemType belongsTo (MenuItem, MenuType) MenuSubtype hasOne (MenuItemSubtype) MenuItemSubtype belongsTo (MenuItem, MenuSubtype) From MenuItemsController, I have no problem getting MenuItem, MenuItemType, and MenuItemSubtype but I can't get MenuType or MenuSubtype. How do I get those? Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.comcake-php%2bunsubscr...@googlegroups.comFor more options, visit this group at http://groups.google.com/group/cake-php?hl=en Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Model association problem
Here are some of the table fields. it's the table USER, GROUPS and MEDICIANL DEVICE. In short relatons are: ser should be in one group and have many MedDevice, group should have one user, medicinal device should have only one user. CREATE TABLE IF NOT EXISTS `baza2`.`USER` ( `id` INT NOT NULL AUTO_INCREMENT , `UserName` VARCHAR(45) NULL , `Password` VARCHAR(45) NULL COMMENT ' ' , `Surname` VARCHAR(45) NULL , `Name` VARCHAR(45) NULL , `groups_id` INT NULL , PRIMARY KEY (`id`) , INDEX `fk_USER_GROUPS` (`groups_id` ASC) , CONSTRAINT `fk_USER_GROUPS` FOREIGN KEY (`groups_id` ) REFERENCES `baza2`.`GROUPS` (`id` ) ON DELETE CASCADE ON UPDATE CASCADE) ENGINE = InnoDB; -- - -- Table `baza2`.`MANUFACTURER` -- - CREATE TABLE IF NOT EXISTS `baza2`.`MANUFACTURER` ( `id` INT NOT NULL AUTO_INCREMENT , `Name` VARCHAR(45) NULL , `Address` VARCHAR(45) NULL , `Phone` VARCHAR(45) NULL , `Contact` VARCHAR(45) NULL , `Mail` VARCHAR(45) NULL , `user_id` INT NULL , PRIMARY KEY (`id`) , INDEX `fk_MANUFACTURER_USER` (`user_id` ASC) , CONSTRAINT `fk_MANUFACTURER_USER` FOREIGN KEY (`user_id` ) REFERENCES `baza2`.`USER` (`id` ) ON DELETE CASCADE ON UPDATE CASCADE) ENGINE = InnoDB; -- - -- Table `baza2`.`MEDICINAL_DEVICE` -- - CREATE TABLE IF NOT EXISTS `baza2`.`MEDICINAL_DEVICE` ( `id` INT NOT NULL AUTO_INCREMENT , `Name` VARCHAR(45) CHARACTER SET 'big5' COLLATE 'big5_chinese_ci' NULL COMMENT '' , `ActiveIng` VARCHAR(45) NULL , `PharmaForm` VARCHAR(45) NULL , `RouteAdministration` VARCHAR(45) NULL , `DailyDose` VARCHAR(45) NULL , `user_id` INT NULL , `manufacturer_id` INT NULL , PRIMARY KEY (`id`) , INDEX `fk_MEDICINAL_DEVICE_USER` (`user_id` ASC) , INDEX `fk_MEDICINAL_DEVICE_MANUFACTURER` (`manufacturer_id` ASC) , CONSTRAINT `fk_MEDICINAL_DEVICE_USER` FOREIGN KEY (`user_id` ) REFERENCES `baza2`.`USER` (`id` ) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `fk_MEDICINAL_DEVICE_MANUFACTURER` FOREIGN KEY (`manufacturer_id` ) REFERENCES `baza2`.`MANUFACTURER` (`id` ) ON DELETE CASCADE ON UPDATE CASCADE) ENGINE = InnoDB; On Thu, Jul 16, 2009 at 4:02 PM, Carlos Gonzalez Lavin carloslavi...@gmail.com wrote: Maybe if you described the tables' fields.. theres gotta be some convention breaking there 2009/7/16 Zoran Kovac zoko2...@gmail.com Hi! I'm having a dilema, maybe the better word is that I'm puzzled. The problem is when I'm baking models. The console doesn't detect relations between tables automatically. For instance, the console does recognize all the tables from the database, but when it's triying to detect associations it comes up with the result like on the end of this post or just skips to 'Look okay?'. It the noted example on end of the post, I manage to create a complete model (with association to user), but association among other models fails. So my question's are: 1. Am I breaking some convetions and it's not working? 2. Could it be that I'm using InnoDB type? 3. Anything else? Any kind of sugestions is appreciated. Thnx. Possible Models based on your current database: 1. DocumentsDevice 2. Group 3. InvestigationalSite 4. Investigator 5. Manufacturer 6. MedicinalDevice 7. MedicinalProduct 8. ReportDevice 9. ReportProduct 10. SoaDevice 11. SoaProduct 12. User Enter a number from the list above, type in the name of another model, or 'q' to exit [q] 2 Would you like to supply validation criteria for the fields in your model? (y/n) [y] n Would you like to define model associations (hasMany, hasOne, belongsTo, etc.)? (y/n) [y] y One moment while the associations are detected. --- Please confirm the following associations: --- Would you like to define some additional model associations? (y/n) [n] -- Zoran Kovac 091/ 588 6175 V.Gorica --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Model association problem
The database table names ought to be plural, viz: MEDICINAL_DEVICES, USERS etc. Cake is intelligent enough to handle plurals such as COMPANIES (COMPANY). In the model definitions, the model will be the capitalised singular version of the tablename, e.g. User Foreign keys are singular, e.g. user_id All these things can be changed where required, but will generally break the bake if they don't follow the convention. see: http://book.cakephp.org/view/24/Model-and-Database-Conventions --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Model association problem
Tables are supposed to be plural (users,groups,medicinal_devices) and the foreign keys singular(user_id,group_id...) Change it and give it another shot =) 2009/7/17 Zoran Kovac zoko2...@gmail.com Here are some of the table fields. it's the table USER, GROUPS and MEDICIANL DEVICE. In short relatons are: ser should be in one group and have many MedDevice, group should have one user, medicinal device should have only one user. CREATE TABLE IF NOT EXISTS `baza2`.`USER` ( `id` INT NOT NULL AUTO_INCREMENT , `UserName` VARCHAR(45) NULL , `Password` VARCHAR(45) NULL COMMENT ' ' , `Surname` VARCHAR(45) NULL , `Name` VARCHAR(45) NULL , `groups_id` INT NULL , PRIMARY KEY (`id`) , INDEX `fk_USER_GROUPS` (`groups_id` ASC) , CONSTRAINT `fk_USER_GROUPS` FOREIGN KEY (`groups_id` ) REFERENCES `baza2`.`GROUPS` (`id` ) ON DELETE CASCADE ON UPDATE CASCADE) ENGINE = InnoDB; -- - -- Table `baza2`.`MANUFACTURER` -- - CREATE TABLE IF NOT EXISTS `baza2`.`MANUFACTURER` ( `id` INT NOT NULL AUTO_INCREMENT , `Name` VARCHAR(45) NULL , `Address` VARCHAR(45) NULL , `Phone` VARCHAR(45) NULL , `Contact` VARCHAR(45) NULL , `Mail` VARCHAR(45) NULL , `user_id` INT NULL , PRIMARY KEY (`id`) , INDEX `fk_MANUFACTURER_USER` (`user_id` ASC) , CONSTRAINT `fk_MANUFACTURER_USER` FOREIGN KEY (`user_id` ) REFERENCES `baza2`.`USER` (`id` ) ON DELETE CASCADE ON UPDATE CASCADE) ENGINE = InnoDB; -- - -- Table `baza2`.`MEDICINAL_DEVICE` -- - CREATE TABLE IF NOT EXISTS `baza2`.`MEDICINAL_DEVICE` ( `id` INT NOT NULL AUTO_INCREMENT , `Name` VARCHAR(45) CHARACTER SET 'big5' COLLATE 'big5_chinese_ci' NULL COMMENT '' , `ActiveIng` VARCHAR(45) NULL , `PharmaForm` VARCHAR(45) NULL , `RouteAdministration` VARCHAR(45) NULL , `DailyDose` VARCHAR(45) NULL , `user_id` INT NULL , `manufacturer_id` INT NULL , PRIMARY KEY (`id`) , INDEX `fk_MEDICINAL_DEVICE_USER` (`user_id` ASC) , INDEX `fk_MEDICINAL_DEVICE_MANUFACTURER` (`manufacturer_id` ASC) , CONSTRAINT `fk_MEDICINAL_DEVICE_USER` FOREIGN KEY (`user_id` ) REFERENCES `baza2`.`USER` (`id` ) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `fk_MEDICINAL_DEVICE_MANUFACTURER` FOREIGN KEY (`manufacturer_id` ) REFERENCES `baza2`.`MANUFACTURER` (`id` ) ON DELETE CASCADE ON UPDATE CASCADE) ENGINE = InnoDB; On Thu, Jul 16, 2009 at 4:02 PM, Carlos Gonzalez Lavin carloslavi...@gmail.com wrote: Maybe if you described the tables' fields.. theres gotta be some convention breaking there 2009/7/16 Zoran Kovac zoko2...@gmail.com Hi! I'm having a dilema, maybe the better word is that I'm puzzled. The problem is when I'm baking models. The console doesn't detect relations between tables automatically. For instance, the console does recognize all the tables from the database, but when it's triying to detect associations it comes up with the result like on the end of this post or just skips to 'Look okay?'. It the noted example on end of the post, I manage to create a complete model (with association to user), but association among other models fails. So my question's are: 1. Am I breaking some convetions and it's not working? 2. Could it be that I'm using InnoDB type? 3. Anything else? Any kind of sugestions is appreciated. Thnx. Possible Models based on your current database: 1. DocumentsDevice 2. Group 3. InvestigationalSite 4. Investigator 5. Manufacturer 6. MedicinalDevice 7. MedicinalProduct 8. ReportDevice 9. ReportProduct 10. SoaDevice 11. SoaProduct 12. User Enter a number from the list above, type in the name of another model, or 'q' to exit [q] 2 Would you like to supply validation criteria for the fields in your model? (y/n) [y] n Would you like to define model associations (hasMany, hasOne, belongsTo, etc.)? (y/n) [y] y One moment while the associations are detected. --- Please confirm the following associations: --- Would you like to define some additional model associations? (y/n) [n] -- Zoran Kovac 091/ 588 6175 V.Gorica --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this
Re: Model association problem
Aargh...name conventions, still not used to it. Thanks for the heads up, knew it had to be something obvoius. It always is ;)) Now it works like a charm. -- Zoran Kovac 091/ 588 6175 V.Gorica On Fri, Jul 17, 2009 at 9:53 AM, Carlos Lavin carloslavi...@gmail.comwrote: Tables are supposed to be plural (users,groups,medicinal_devices) and the foreign keys singular(user_id,group_id...) Change it and give it another shot =) 2009/7/17 Zoran Kovac zoko2...@gmail.com Here are some of the table fields. it's the table USER, GROUPS and MEDICIANL DEVICE. In short relatons are: ser should be in one group and have many MedDevice, group should have one user, medicinal device should have only one user. CREATE TABLE IF NOT EXISTS `baza2`.`USER` ( `id` INT NOT NULL AUTO_INCREMENT , `UserName` VARCHAR(45) NULL , `Password` VARCHAR(45) NULL COMMENT ' ' , `Surname` VARCHAR(45) NULL , `Name` VARCHAR(45) NULL , `groups_id` INT NULL , PRIMARY KEY (`id`) , INDEX `fk_USER_GROUPS` (`groups_id` ASC) , CONSTRAINT `fk_USER_GROUPS` FOREIGN KEY (`groups_id` ) REFERENCES `baza2`.`GROUPS` (`id` ) ON DELETE CASCADE ON UPDATE CASCADE) ENGINE = InnoDB; -- - -- Table `baza2`.`MANUFACTURER` -- - CREATE TABLE IF NOT EXISTS `baza2`.`MANUFACTURER` ( `id` INT NOT NULL AUTO_INCREMENT , `Name` VARCHAR(45) NULL , `Address` VARCHAR(45) NULL , `Phone` VARCHAR(45) NULL , `Contact` VARCHAR(45) NULL , `Mail` VARCHAR(45) NULL , `user_id` INT NULL , PRIMARY KEY (`id`) , INDEX `fk_MANUFACTURER_USER` (`user_id` ASC) , CONSTRAINT `fk_MANUFACTURER_USER` FOREIGN KEY (`user_id` ) REFERENCES `baza2`.`USER` (`id` ) ON DELETE CASCADE ON UPDATE CASCADE) ENGINE = InnoDB; -- - -- Table `baza2`.`MEDICINAL_DEVICE` -- - CREATE TABLE IF NOT EXISTS `baza2`.`MEDICINAL_DEVICE` ( `id` INT NOT NULL AUTO_INCREMENT , `Name` VARCHAR(45) CHARACTER SET 'big5' COLLATE 'big5_chinese_ci' NULL COMMENT '' , `ActiveIng` VARCHAR(45) NULL , `PharmaForm` VARCHAR(45) NULL , `RouteAdministration` VARCHAR(45) NULL , `DailyDose` VARCHAR(45) NULL , `user_id` INT NULL , `manufacturer_id` INT NULL , PRIMARY KEY (`id`) , INDEX `fk_MEDICINAL_DEVICE_USER` (`user_id` ASC) , INDEX `fk_MEDICINAL_DEVICE_MANUFACTURER` (`manufacturer_id` ASC) , CONSTRAINT `fk_MEDICINAL_DEVICE_USER` FOREIGN KEY (`user_id` ) REFERENCES `baza2`.`USER` (`id` ) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `fk_MEDICINAL_DEVICE_MANUFACTURER` FOREIGN KEY (`manufacturer_id` ) REFERENCES `baza2`.`MANUFACTURER` (`id` ) ON DELETE CASCADE ON UPDATE CASCADE) ENGINE = InnoDB; On Thu, Jul 16, 2009 at 4:02 PM, Carlos Gonzalez Lavin carloslavi...@gmail.com wrote: Maybe if you described the tables' fields.. theres gotta be some convention breaking there 2009/7/16 Zoran Kovac zoko2...@gmail.com Hi! I'm having a dilema, maybe the better word is that I'm puzzled. The problem is when I'm baking models. The console doesn't detect relations between tables automatically. For instance, the console does recognize all the tables from the database, but when it's triying to detect associations it comes up with the result like on the end of this post or just skips to 'Look okay?'. It the noted example on end of the post, I manage to create a complete model (with association to user), but association among other models fails. So my question's are: 1. Am I breaking some convetions and it's not working? 2. Could it be that I'm using InnoDB type? 3. Anything else? Any kind of sugestions is appreciated. Thnx. Possible Models based on your current database: 1. DocumentsDevice 2. Group 3. InvestigationalSite 4. Investigator 5. Manufacturer 6. MedicinalDevice 7. MedicinalProduct 8. ReportDevice 9. ReportProduct 10. SoaDevice 11. SoaProduct 12. User Enter a number from the list above, type in the name of another model, or 'q' to exit [q] 2 Would you like to supply validation criteria for the fields in your model? (y/n) [y] n Would you like to define model associations (hasMany, hasOne, belongsTo, etc.)? (y/n) [y] y One moment while the associations are detected. --- Please confirm the following associations: --- Would you like to define some additional model associations? (y/n) [n] -- Zoran Kovac 091/ 588 6175 V.Gorica
Model association problem
Hi! I'm having a dilema, maybe the better word is that I'm puzzled. The problem is when I'm baking models. The console doesn't detect relations between tables automatically. For instance, the console does recognize all the tables from the database, but when it's triying to detect associations it comes up with the result like on the end of this post or just skips to 'Look okay?'. It the noted example on end of the post, I manage to create a complete model (with association to user), but association among other models fails. So my question's are: 1. Am I breaking some convetions and it's not working? 2. Could it be that I'm using InnoDB type? 3. Anything else? Any kind of sugestions is appreciated. Thnx. Possible Models based on your current database: 1. DocumentsDevice 2. Group 3. InvestigationalSite 4. Investigator 5. Manufacturer 6. MedicinalDevice 7. MedicinalProduct 8. ReportDevice 9. ReportProduct 10. SoaDevice 11. SoaProduct 12. User Enter a number from the list above, type in the name of another model, or 'q' to exit [q] 2 Would you like to supply validation criteria for the fields in your model? (y/n) [y] n Would you like to define model associations (hasMany, hasOne, belongsTo, etc.)? (y/n) [y] y One moment while the associations are detected. --- Please confirm the following associations: --- Would you like to define some additional model associations? (y/n) [n] --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Model association problem
Maybe if you described the tables' fields.. theres gotta be some convention breaking there 2009/7/16 Zoran Kovac zoko2...@gmail.com Hi! I'm having a dilema, maybe the better word is that I'm puzzled. The problem is when I'm baking models. The console doesn't detect relations between tables automatically. For instance, the console does recognize all the tables from the database, but when it's triying to detect associations it comes up with the result like on the end of this post or just skips to 'Look okay?'. It the noted example on end of the post, I manage to create a complete model (with association to user), but association among other models fails. So my question's are: 1. Am I breaking some convetions and it's not working? 2. Could it be that I'm using InnoDB type? 3. Anything else? Any kind of sugestions is appreciated. Thnx. Possible Models based on your current database: 1. DocumentsDevice 2. Group 3. InvestigationalSite 4. Investigator 5. Manufacturer 6. MedicinalDevice 7. MedicinalProduct 8. ReportDevice 9. ReportProduct 10. SoaDevice 11. SoaProduct 12. User Enter a number from the list above, type in the name of another model, or 'q' to exit [q] 2 Would you like to supply validation criteria for the fields in your model? (y/n) [y] n Would you like to define model associations (hasMany, hasOne, belongsTo, etc.)? (y/n) [y] y One moment while the associations are detected. --- Please confirm the following associations: --- Would you like to define some additional model associations? (y/n) [n] --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
saveAll() and hasOne association problem
What do I need to do so that saveAll() will automatically add the correct member_id for this: http://bin.cakephp.org/view/59481259 I have a EmergencyLoan hasOne Beneficiary which uses saveAll() that works perfectly. I can't seem to find what's wrong with the Member hasOne Spouse --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: saveAll() and hasOne association problem
Removing the bind/unbindModel() 'fixes' the problem. But I think I need to have the bind/unbind since the member may/may not have a spouse. On Feb 23, 6:25 pm, ramonmaruko ramonmar...@gmail.com wrote: What do I need to do so that saveAll() will automatically add the correct member_id for this:http://bin.cakephp.org/view/59481259 I have a EmergencyLoan hasOne Beneficiary which uses saveAll() that works perfectly. I can't seem to find what's wrong with the Member hasOne Spouse --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: saveAll() and hasOne association problem
It works now. :) I removed the bind/unbindModel() calls and replaced them. http://bin.cakephp.org/view/38527196 ramonmaruko wrote: Removing the bind/unbindModel() 'fixes' the problem. But I think I need to have the bind/unbind since the member may/may not have a spouse. On Feb 23, 6:25 pm, ramonmaruko ramonmar...@gmail.com wrote: What do I need to do so that saveAll() will automatically add the correct member_id for this:http://bin.cakephp.org/view/59481259 I have a EmergencyLoan hasOne Beneficiary which uses saveAll() that works perfectly. I can't seem to find what's wrong with the Member hasOne Spouse --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Auth - User model association problem
Hi, I have a User model, which belongsTo a Group model. When using the user model itself, I get the correct association data for the Group model, but when using the Auth component, then I only get the User model itself in the auth session array, e.g.: [Auth] = Array ( [User] = Array ( [id] = 2 [username] = admin [group_id] = 1 ) ) whereas I would expect something like: [Auth] = Array ( [User] = Array ( [id] = 2 [username] = admin [group_id] = 1 ) [Group] = Array ( [id] = 1 [name] = Admins ) ) Is the Auth component ignoring the User model associations? Thanks. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Plugin Model Association Problem
Add var $name = 'User'; var $name = 'UserProfile'; as properties in your models and I think you're golden :-) On May 24, 10:19 am, francky06l [EMAIL PROTECTED] wrote: Can you pass your model definition code ? I have the same kind of plugin and not much problems, maybe I declare the association in different way. I set the plugin name into the className parameter ie : belongTo = array('Profile' = array('className' = 'user.Profile') Wich cake version are you using ? On May 24, 12:05 am, Christopher E. Franklin, Sr. [EMAIL PROTECTED] wrote: On May 23, 2:49 pm, francky06l [EMAIL PROTECTED] wrote: If the user model is in the plugin it should not a problem.. Maybe the problem is how you call the find and from where ? I do the find in the UsersController::read() function. It seems to me that it is a problem with the association because, when I set $this-User-recursive = -1; I get back just the user. But, anything else, it tries to pull the UserProfile and screws up. I guess this is when you try to find user from the application and not the plugin ? No, I make the call from the users_controller in the plugin. Maybe the problem comes from the calling rather than the callee ? I don't see a problem with $this-User-findById(1); but, like I said, if I set recursive to -1 I get the user I want but, not the user_profile. I wanted to get both. Alternatively, I can set the UserModel and UserProfileModel both to recursive = -1 and just live with the extra calls but, this would be a pain if I want to find all users. I have also tried declaring different $hasOne and $belongsTo without the plugin name like, 'User' instead of 'users.User' but, if I do that, it says that it cannot find the database table user_profiles for the 'UserProfile' model. hth Thank you for replying :) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Plugin Model Association Problem
Can you pass your model definition code ? I have the same kind of plugin and not much problems, maybe I declare the association in different way. I set the plugin name into the className parameter ie : belongTo = array('Profile' = array('className' = 'user.Profile') Wich cake version are you using ? On May 24, 12:05 am, Christopher E. Franklin, Sr. [EMAIL PROTECTED] wrote: On May 23, 2:49 pm, francky06l [EMAIL PROTECTED] wrote: If the user model is in the plugin it should not a problem.. Maybe the problem is how you call the find and from where ? I do the find in the UsersController::read() function. It seems to me that it is a problem with the association because, when I set $this-User-recursive = -1; I get back just the user. But, anything else, it tries to pull the UserProfile and screws up. I guess this is when you try to find user from the application and not the plugin ? No, I make the call from the users_controller in the plugin. Maybe the problem comes from the calling rather than the callee ? I don't see a problem with $this-User-findById(1); but, like I said, if I set recursive to -1 I get the user I want but, not the user_profile. I wanted to get both. Alternatively, I can set the UserModel and UserProfileModel both to recursive = -1 and just live with the extra calls but, this would be a pain if I want to find all users. I have also tried declaring different $hasOne and $belongsTo without the plugin name like, 'User' instead of 'users.User' but, if I do that, it says that it cannot find the database table user_profiles for the 'UserProfile' model. hth Thank you for replying :) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Plugin Model Association Problem
Hi great coders, I am having a problem trying to get my model associations in a plugin to come through. I have a plugin called users and I have a users_controller and a user_profiles_controller and thier associated models. Between these two models, I have them associated as, user has one user profile and the user profile belongs to a user. In my controller, since I want to save the profile information at the same time as I create the user, I have to declare the $uses array. This is fine but, since I am in a plugin, I have to declare these like so: public $uses = array('users.User', 'users.UserProfile'); This works perfectly and I can create a user and a user profile and it saves just fine. The problem is when I try to find the user. In my model association I have to have: $belongsTo = 'users.User'; and $hasOne = 'users.UserProfile'; or else it will say that it cannot find the correct table. Now, with this set, I get a giant SQL statement with an error: Query: SELECT `User`.`id`, `User`.`email`, `User`.`password`, `User`.`group_id`, `User`.`created`, `User`.`updated`, `User`.`modified`, `users`.`UserProfile`.`id`, `users`.`UserProfile`.`first_name`, `users`.`UserProfile`.`last_name`, `users`.`UserProfile`.`address`, `users`.`UserProfile`.`city`, `users`.`UserProfile`.`state`, `users`.`UserProfile`.`zip`, `users`.`UserProfile`.`province`, `users`.`UserProfile`.`country`, `users`.`UserProfile`.`home_telephone`, `users`.`UserProfile`.`cell_phone`, `users`.`UserProfile`.`fax`, `users`.`UserProfile`.`user_id` FROM `users` AS `User` LEFT JOIN `user_profiles` AS `users`.`UserProfile` ON (`users`.`UserProfile`.user_id = `User`.`id`) WHERE 1 = 1 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.`UserProfile` ON (`users`.`UserProfile`.user_id = `User`.`id`) WHERE 1 = 1' at line 1 To me, it looks like the error is in the statement where it says users.UserProfile ON users.UserProfile.user_id So, I am at a loss, can't find anything here on the group, or the tickets and IRC isn't very helpful today. So, here is the code I have, maybe a second set of eyes will see something I dont. Remember, this is in a plugin. USERS_CONTROLLER - /app/plugins/users/controllers/users_controller.php --- class UsersController extends UsersAppController { public $components = array('Auth'); public $uses = array('users.User', 'users.UserProfile'); public function beforeFilter() { parent::beforeFilter(); $this-Auth-loginAction = '/login'; $this-Auth-logoutAction = '/logout'; $this-Auth-allowedActions = array('index', 'create', 'read', 'update', 'delete'); } public function index() { } public function create() { if(!empty($this-data)) { $this-data['User']['password'] = $this-Auth-password($this- data['User']['password']); $this-User-create($this-data); $this-User-save($this-data); $user_id = $this-User-id; $this-data['UserProfile']['id'] = $user_id; $this-data['UserProfile']['user_id'] = $user_id; $this-UserProfile-create($this-data); $this-UserProfile-save($this-data); } $this-set('fields', $this-User-getColumnTypes()); } public function read($id = 1) { $this-set('user', $this-User-findById($id)); } public function update($id = 1) { $this-set('user', $this-User-findById($id)); } public function delete() { } } USER_MODEL - /app/plugins/users/models/user.php --- class User extends UsersAppModel { public $useDbConfig = 'users'; public $hasOne = 'users.UserProfile'; } USER_PROFILE_MODEL - /app/plugins/users/models/user_profile.php -- class UserProfile extends UsersAppModel { public $useDbConfig = 'users'; public $belongsTo = 'users.User'; } --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Plugin Model Association Problem
If the user model is in the plugin it should not a problem.. Maybe the problem is how you call the find and from where ? The problem is when I try to find the user. In my model association I have to have: I guess this is when you try to find user from the application and not the plugin ? Maybe the problem comes from the calling rather than the callee ? hth On May 23, 7:34 pm, Christopher E. Franklin, Sr. [EMAIL PROTECTED] wrote: Hi great coders, I am having a problem trying to get my model associations in a plugin to come through. I have a plugin called users and I have a users_controller and a user_profiles_controller and thier associated models. Between these two models, I have them associated as, user has one user profile and the user profile belongs to a user. In my controller, since I want to save the profile information at the same time as I create the user, I have to declare the $uses array. This is fine but, since I am in a plugin, I have to declare these like so: public $uses = array('users.User', 'users.UserProfile'); This works perfectly and I can create a user and a user profile and it saves just fine. The problem is when I try to find the user. In my model association I have to have: $belongsTo = 'users.User'; and $hasOne = 'users.UserProfile'; or else it will say that it cannot find the correct table. Now, with this set, I get a giant SQL statement with an error: Query: SELECT `User`.`id`, `User`.`email`, `User`.`password`, `User`.`group_id`, `User`.`created`, `User`.`updated`, `User`.`modified`, `users`.`UserProfile`.`id`, `users`.`UserProfile`.`first_name`, `users`.`UserProfile`.`last_name`, `users`.`UserProfile`.`address`, `users`.`UserProfile`.`city`, `users`.`UserProfile`.`state`, `users`.`UserProfile`.`zip`, `users`.`UserProfile`.`province`, `users`.`UserProfile`.`country`, `users`.`UserProfile`.`home_telephone`, `users`.`UserProfile`.`cell_phone`, `users`.`UserProfile`.`fax`, `users`.`UserProfile`.`user_id` FROM `users` AS `User` LEFT JOIN `user_profiles` AS `users`.`UserProfile` ON (`users`.`UserProfile`.user_id = `User`.`id`) WHERE 1 = 1 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.`UserProfile` ON (`users`.`UserProfile`.user_id = `User`.`id`) WHERE 1 = 1' at line 1 To me, it looks like the error is in the statement where it says users.UserProfile ON users.UserProfile.user_id So, I am at a loss, can't find anything here on the group, or the tickets and IRC isn't very helpful today. So, here is the code I have, maybe a second set of eyes will see something I dont. Remember, this is in a plugin. USERS_CONTROLLER - /app/plugins/users/controllers/users_controller.php --- class UsersController extends UsersAppController { public $components = array('Auth'); public $uses = array('users.User', 'users.UserProfile'); public function beforeFilter() { parent::beforeFilter(); $this-Auth-loginAction = '/login'; $this-Auth-logoutAction = '/logout'; $this-Auth-allowedActions = array('index', 'create', 'read', 'update', 'delete'); } public function index() { } public function create() { if(!empty($this-data)) { $this-data['User']['password'] = $this-Auth-password($this-data['User']['password']); $this-User-create($this-data); $this-User-save($this-data); $user_id = $this-User-id; $this-data['UserProfile']['id'] = $user_id; $this-data['UserProfile']['user_id'] = $user_id; $this-UserProfile-create($this-data); $this-UserProfile-save($this-data); } $this-set('fields', $this-User-getColumnTypes()); } public function read($id = 1) { $this-set('user', $this-User-findById($id)); } public function update($id = 1) { $this-set('user', $this-User-findById($id)); } public function delete() { } } USER_MODEL - /app/plugins/users/models/user.php --- class User extends UsersAppModel { public $useDbConfig = 'users'; public $hasOne = 'users.UserProfile'; } USER_PROFILE_MODEL - /app/plugins/users/models/user_profile.php -- class UserProfile extends UsersAppModel { public $useDbConfig = 'users'; public $belongsTo = 'users.User'; } --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to
Re: Plugin Model Association Problem
On May 23, 2:49 pm, francky06l [EMAIL PROTECTED] wrote: If the user model is in the plugin it should not a problem.. Maybe the problem is how you call the find and from where ? I do the find in the UsersController::read() function. It seems to me that it is a problem with the association because, when I set $this- User-recursive = -1; I get back just the user. But, anything else, it tries to pull the UserProfile and screws up. I guess this is when you try to find user from the application and not the plugin ? No, I make the call from the users_controller in the plugin. Maybe the problem comes from the calling rather than the callee ? I don't see a problem with $this-User-findById(1); but, like I said, if I set recursive to -1 I get the user I want but, not the user_profile. I wanted to get both. Alternatively, I can set the UserModel and UserProfileModel both to recursive = -1 and just live with the extra calls but, this would be a pain if I want to find all users. I have also tried declaring different $hasOne and $belongsTo without the plugin name like, 'User' instead of 'users.User' but, if I do that, it says that it cannot find the database table user_profiles for the 'UserProfile' model. hth Thank you for replying :) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Multiple table association problem
I think I'm confusing myself. I've read several posts, but haven't got the right solution. I have a model called Properties that facilitates the addition, deletion, or editing of a property. Each property has 300 questions tied to it. These question answers (boolean true/false) are found in the Answer model. The table structure for the answer model is: ID, question_id, property_id, response The question model allows addition or deletion of questions, and its structure is: id, question, points, category_id The category model allows addition or deletion of categories, and its structure is: id, name So. When a user creates a property, they then need to respond to the 300 questions. Each question response is a row entry into the answers table. The end result needs to be a property array that has the property information, question, answer, and the category that each question belongs in. As of right now, I have a hasAndBelongsToMany between Property and Answer, so I'm able to see the property information in the array, and the answers -- but I need to relate the questions in there too (based off of the question ID that's in the answer). Any ideas? I tried doing a multiple HABTM -- but it didn't quite turn out right. I know I could do this manually, but I want to do it correctly so I can save time in the future. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Simple association problem
Hi, I am having some problems with belongTo, here is my code: Model: ?php class Document extends AppModel { var $belongTo= array( 'Recorder' = array('className'= 'Recorder', 'conditions' = '', 'order'= '', 'dependent'= true, 'foreignKey' = 'recorder_id' ); } ? ?php class Recorder extends AppModel { } ? Table: DROP TABLE IF EXISTS `recorders`; CREATE TABLE `recorders` ( `id` int(10) unsigned NOT NULL auto_increment, `titulo` varchar(45) NOT NULL, `fecha_desde` datetime NOT NULL COMMENT 'fecha minima de creacion de documentos a archivar en el bibliorato', `fecha_hasta` datetime default NULL COMMENT 'fecha maxima de creacion de documentos a archivar en el bibliorato', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; ROP TABLE IF EXISTS `documents`; CREATE TABLE `documents` ( `id` int(10) unsigned NOT NULL auto_increment, `recorder_id` int(10) unsigned NOT NULL COMMENT 'Id de bibliorato en que este documento esta almacenado. Si es NULL, el documento no esta archivado', `proposito` int(10) unsigned NOT NULL COMMENT 'Representa el proposito compuesto del documento (solicitud [notificacion], respuesta [notificacion]). El bit mas bajo es solicitud, el siguiente es respuesta y el 3ero es notificacion', `tipo` int(10) unsigned NOT NULL COMMENT '1: Nota, 2: Memo, 3: Resolucion, 4: Expediente.', `fecha_creacion` datetime NOT NULL, `asunto` varchar(500) NOT NULL, `observacion` varchar(1000) default NULL, `despacho` int(10) unsigned NOT NULL COMMENT 'De intercambio (1) o providencia (2). Tiene relacion con el campo TIPO', `tipo_resolucion` int(10) unsigned default NULL COMMENT '(Solo si TIPO = Resolucion). De Decano (1), Consejo Directivo (2), Rector (3), Consejo Superior (4)', `numero_resolucion` varchar(50) default NULL COMMENT '(Solo si TIPO = Resolucion).', `numero_expediente` varchar(50) default NULL COMMENT '(Solo si TIPO = Expediente). No es el ID de expediente, es el numero interno de la facultad que le asigna al expediente.', `fecha_ingreso` datetime default NULL COMMENT 'fecha de ingreso del documento a la dependencia', `fecha_egreso` datetime default NULL COMMENT 'fecha de egreso del documento de la dependencia.', PRIMARY KEY (`id`) ) ; The problem is that cake doesn't make the association between tables, when I do: $this-set('doc', $this-Document-read(null, '1')) ; ?php print_r($doc)? Output: Array ( [Document] = Array ( [id] = 1 [recorder_id] = 1 [proposito] = 0 [tipo] = 0 [fecha_creacion] = -00-00 00:00:00 [asunto] = as [observacion] = as [despacho] = 0 [tipo_resolucion] = [numero_resolucion] = [numero_expediente] = [fecha_ingreso] = -00-00 00:00:00 [fecha_egreso] = -00-00 00:00:00 ) No recorder data, only its id I hope someone can help me with this problem, Thank you very much and sorry about my english, it is no good --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Simple association problem
Maybe set DEBUG to 2 and look at the SQL being generated. Does $this-Document-findById(1) return the same thing? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Simple association problem
Perhaps try: var $belongsTo = array( (Note the 's' in there!) Mauro wrote: Hi, I am having some problems with belongTo, here is my code: Model: ?php class Document extends AppModel { var $belongTo= array( 'Recorder' = array('className'= 'Recorder', 'conditions' = '', 'order'= '', 'dependent'= true, 'foreignKey' = 'recorder_id' ); } ? ?php class Recorder extends AppModel { } ? Table: DROP TABLE IF EXISTS `recorders`; CREATE TABLE `recorders` ( `id` int(10) unsigned NOT NULL auto_increment, `titulo` varchar(45) NOT NULL, `fecha_desde` datetime NOT NULL COMMENT 'fecha minima de creacion de documentos a archivar en el bibliorato', `fecha_hasta` datetime default NULL COMMENT 'fecha maxima de creacion de documentos a archivar en el bibliorato', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; ROP TABLE IF EXISTS `documents`; CREATE TABLE `documents` ( `id` int(10) unsigned NOT NULL auto_increment, `recorder_id` int(10) unsigned NOT NULL COMMENT 'Id de bibliorato en que este documento esta almacenado. Si es NULL, el documento no esta archivado', `proposito` int(10) unsigned NOT NULL COMMENT 'Representa el proposito compuesto del documento (solicitud [notificacion], respuesta [notificacion]). El bit mas bajo es solicitud, el siguiente es respuesta y el 3ero es notificacion', `tipo` int(10) unsigned NOT NULL COMMENT '1: Nota, 2: Memo, 3: Resolucion, 4: Expediente.', `fecha_creacion` datetime NOT NULL, `asunto` varchar(500) NOT NULL, `observacion` varchar(1000) default NULL, `despacho` int(10) unsigned NOT NULL COMMENT 'De intercambio (1) o providencia (2). Tiene relacion con el campo TIPO', `tipo_resolucion` int(10) unsigned default NULL COMMENT '(Solo si TIPO = Resolucion). De Decano (1), Consejo Directivo (2), Rector (3), Consejo Superior (4)', `numero_resolucion` varchar(50) default NULL COMMENT '(Solo si TIPO = Resolucion).', `numero_expediente` varchar(50) default NULL COMMENT '(Solo si TIPO = Expediente). No es el ID de expediente, es el numero interno de la facultad que le asigna al expediente.', `fecha_ingreso` datetime default NULL COMMENT 'fecha de ingreso del documento a la dependencia', `fecha_egreso` datetime default NULL COMMENT 'fecha de egreso del documento de la dependencia.', PRIMARY KEY (`id`) ) ; The problem is that cake doesn't make the association between tables, when I do: $this-set('doc', $this-Document-read(null, '1')) ; ?php print_r($doc)? Output: Array ( [Document] = Array ( [id] = 1 [recorder_id] = 1 [proposito] = 0 [tipo] = 0 [fecha_creacion] = -00-00 00:00:00 [asunto] = as [observacion] = as [despacho] = 0 [tipo_resolucion] = [numero_resolucion] = [numero_expediente] = [fecha_ingreso] = -00-00 00:00:00 [fecha_egreso] = -00-00 00:00:00 ) No recorder data, only its id I hope someone can help me with this problem, Thank you very much and sorry about my english, it is no good -- Joshua Benner http://bennerweb.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Simple association problem
Thank you all! the `s` wasn't there, it is true :( I hate when tthis happen Thanks --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Model association problem
Hi! Im in quite a fix. I have created 2 tables as of now users username,id,password,name,type(owner/incharge/both),email Primary key - id equipment type,equipmentno,owner,incharge,dateofpurchase Primary key - equipmentno Foreign Keys - owner and incharge. The User hasMany Equipment.Equipment can be owned by only 1 person. I have created a form to add equipment.I need to validate the form by checking whether the user has entered a valid owner name or not. To do this I need to associate the models which I am unable to do. Could you please help me out. Thanks! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Association Problem
Change your Intinerary's Event association to var $hasMany = array('Event' = array('className'= 'Event') ); in your itineraries/view action, have something like function view($id) { $this-Itinerary-recursive = 1; $itinerary = $this-Itinerary-read(null, $id); $this-set('itinerary', $itinerary); } and in your view, do a print_r($itinerary) to see how the associations come through in your data array. Or, just bake the whole lot - it can make all your models, controllers and views, just make sure you tell it the right associations. On Feb 17, 11:26 am, strykstaguy [EMAIL PROTECTED] wrote: I have tried to read the manual and look at examples but I am having a hard time with associations. For one, I have a three tables. Trips, Itineraries, Events Each has one Itinerary, Each Itinerary has many events. What i really want right now is to connect my Itineraries to Events, Currently when i display my itineraries it repeats them 6 times instead of twice (the number of itineraries i have right now). I want once i select an itinerary is to view the events that match that itinerary. itinerary.php *** ? class Itinerary extends AppModel { Var $name = 'Itinerary'; var $hasOne = array('Event' = array('className'= 'Event', 'conditions' = '', 'order'= '', 'dependent'= false, 'foreignKey' = 'itinerary_id' ) ); var $validate = array( 'title' = VALID_NOT_EMPTY, 'creator' = VALID_NOT_EMPTY, 'when' = VALID_NOT_EMPTY ); } ? *** events.php ** ? class Event extends AppModel { Var $name = 'Event'; var $belongsTo = array('Itinerary' = array('className' = 'Itinerary', 'conditions' = '', 'order' = '', 'foreignKey' = 'itinerary_id' ) ); var $validate = array( 'what' = VALID_NOT_EMPTY, 'where' = VALID_NOT_EMPTY, 'andwhen' = VALID_NOT_EMPTY ); } ? * What it all comes down to is I know how to connect them with HasMany and BelongsTo but i don't know how to actually display the events info in the 'View' of my itineraries. Any Help? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Association Problem
sweet, THANK YOU! :) On Feb 17, 6:59 pm, Grant Cox [EMAIL PROTECTED] wrote: Change your Intinerary's Event association to var $hasMany = array('Event' = array('className'= 'Event') ); in your itineraries/view action, have something like function view($id) { $this-Itinerary-recursive = 1; $itinerary = $this-Itinerary-read(null, $id); $this-set('itinerary', $itinerary); } and in your view, do a print_r($itinerary) to see how the associations come through in your data array. Or, just bake the whole lot - it can make all your models, controllers and views, just make sure you tell it the right associations. On Feb 17, 11:26 am, strykstaguy [EMAIL PROTECTED] wrote: I have tried to read the manual and look at examples but I am having a hard time with associations. For one, I have a three tables. Trips, Itineraries, Events Each has one Itinerary, Each Itinerary has many events. What i really want right now is to connect my Itineraries to Events, Currently when i display my itineraries it repeats them 6 times instead of twice (the number of itineraries i have right now). I want once i select an itinerary is to view the events that match that itinerary. itinerary.php *** ? class Itinerary extends AppModel { Var $name = 'Itinerary'; var $hasOne = array('Event' = array('className'= 'Event', 'conditions' = '', 'order'= '', 'dependent'= false, 'foreignKey' = 'itinerary_id' ) ); var $validate = array( 'title' = VALID_NOT_EMPTY, 'creator' = VALID_NOT_EMPTY, 'when' = VALID_NOT_EMPTY ); } ? *** events.php ** ? class Event extends AppModel { Var $name = 'Event'; var $belongsTo = array('Itinerary' = array('className' = 'Itinerary', 'conditions' = '', 'order' = '', 'foreignKey' = 'itinerary_id' ) ); var $validate = array( 'what' = VALID_NOT_EMPTY, 'where' = VALID_NOT_EMPTY, 'andwhen' = VALID_NOT_EMPTY ); } ? * What it all comes down to is I know how to connect them with HasMany and BelongsTo but i don't know how to actually display the events info in the 'View' of my itineraries. Any Help?- Hide quoted text - - Show quoted text - --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Association Problem
I have tried to read the manual and look at examples but I am having a hard time with associations. For one, I have a three tables. Trips, Itineraries, Events Each has one Itinerary, Each Itinerary has many events. What i really want right now is to connect my Itineraries to Events, Currently when i display my itineraries it repeats them 6 times instead of twice (the number of itineraries i have right now). I want once i select an itinerary is to view the events that match that itinerary. itinerary.php *** ? class Itinerary extends AppModel { Var $name = 'Itinerary'; var $hasOne = array('Event' = array('className'= 'Event', 'conditions' = '', 'order'= '', 'dependent'= false, 'foreignKey' = 'itinerary_id' ) ); var $validate = array( 'title' = VALID_NOT_EMPTY, 'creator' = VALID_NOT_EMPTY, 'when' = VALID_NOT_EMPTY ); } ? *** events.php ** ? class Event extends AppModel { Var $name = 'Event'; var $belongsTo = array('Itinerary' = array('className' = 'Itinerary', 'conditions' = '', 'order' = '', 'foreignKey' = 'itinerary_id' ) ); var $validate = array( 'what' = VALID_NOT_EMPTY, 'where' = VALID_NOT_EMPTY, 'andwhen' = VALID_NOT_EMPTY ); } ? * What it all comes down to is I know how to connect them with HasMany and BelongsTo but i don't know how to actually display the events info in the 'View' of my itineraries. Any Help? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Association problem
I have some problems to understand the association. For example, I have a model 'User' and model 'Address'. User: - id - bla bla bla - office_address : int - address.id - home_address : int - address.id How can I define association between this 2 models? Thanks a lot! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Association problem
Here is an example from a project I have that is similar Model JobMaterial var $belongsTo = array( 'Client'= array('className'='Client','foreignKey'='client_id'), 'Photographer' = array('className'='Client','foreignKey'='photographer_id'), 'Billto'= array('className'='Client','foreignKey'='billto_id'), ); Model Client var $hasMany = array( 'JobMaterial_Client'= array('className'='JobMaterial', 'foreignKey'='client_id'), 'JobMaterial_Photograper' = array('className'='JobMaterial', 'foreignKey'='photographer_id'), 'JobMaterial_Billto'= array('className'='JobMaterial', 'foreignKey'='billto_id'), ); see if that gives you a hint On 1/9/07, Alessandro Nuzzo [EMAIL PROTECTED] wrote: I have some problems to understand the association. For example, I have a model 'User' and model 'Address'. User: - id - bla bla bla - office_address : int - address.id - home_address : int - address.id How can I define association between this 2 models? Thanks a lot! -- == S. DeVore (the old fart) the advice is free, the lack of crankiness will cost you --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Association problem
On Jan 9, 2007, at 12:48 PM, Alessandro Nuzzo wrote: I have some problems to understand the association. For example, I have a model 'User' and model 'Address'. User: - id - bla bla bla - office_address : int - address.id - home_address : int - address.id Stick this in your model. var $belongsTo = array('HomeAddress' = array('className' = 'Address', 'conditions' = '', 'order' = '', 'foreignKey' = 'home_address' ), 'OfficeAddress' = array('className' = 'Address', 'conditions' = '', 'order' = '', 'foreignKey' = 'office_address' ) ); (This info can be found in http://manual.cakephp.org/chapter/models ) -- John --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---