Re: Help with associations
You need an additional information - who is friend with whom - so a new table "users_users" is born :) So your relationships will be: "users" hasMany "posts" "users" hasAndBelongsToMany "users" through "users_users". And you have to find: 1) The current users post using "users" hasMany "posts" association. 2) The current users friends posts using both associations "users" hasAndBelongsToMany "users" (friends) hasMany "posts" For 2) you have to lookup recursive and unbindModel/bindModel. Enjoy, John On Apr 20, 2:34 am, Victorr wrote: > I need some help with linking my database tables and models. > > I have: > User > Profile > Post > > A User has many posts, one profile and many friends(other users). I > want to display the users posts and the users friends posts on the > profile. > > How should i build the database(like friendship between users) and the > 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 cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Help with associations
I need some help with linking my database tables and models. I have: User Profile Post A User has many posts, one profile and many friends(other users). I want to display the users posts and the users friends posts on the profile. How should i build the database(like friendship between users) and the 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 cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Need Help with Associations
Hi, I have two tables, franchises and owners. The owners table has a foreign key to franchises called franchise_id. I've defined a $hasMany relationship between franchise and owners (ie. 1 franchise can have many owners). I've defined a $belongsTo relationship between owner and franchise (ie. an owner belongs to a franchise). Now, I'm trying to edit franchise and the associated owner information. However, I can't seem to access the owner information. Here is my franchises_controller.php function for edit: function edit($id = null) { if(empty($this->data['Franchise'])) { $this->Franchise->id = $id; $this->data = $this->Franchise->read(); } else { if($this->Franchise->save($this->data['Franchise'])) { $this->flash('Your franchise has been updated.', '/franchises/'); } } } Here is my edit.thtml file. Please note that I am confused as to how the data is pre-populated in the form and why can't I seem to get the owner associated data pre-populated? I'm also trying to print the $data array, with no success. Edit Franchise hidden('Franchise/id'); ?> Name: input('Franchise/name', array('size' => '40')) ?> Owner First Name: input('Owner/first_name', array('size' => '40')) ?> submit('Save') ?> Any help would be appreciated. Thanks, Jamie --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Help with associations and scaffolding
So I have a cookbook application with recipes and categories: Recipes id:title:recipe:created_on:category_id Categories id:name I am trying to use bake to setup the associations between the categories and recipes: CATEGORY MODEL class Category extends AppModel { var $name = 'Category'; //The Associations below have been created with all possible keys, those that are not needed can be removed var $hasMany = array( 'Recipe' => array('className' => 'Recipe', 'foreignKey' => 'category_id', 'conditions' => '', 'fields' => '', 'order' => '', 'limit' => '', 'offset' => '', 'dependent' => '', 'exclusive' => '', 'finderQuery' => '', 'counterQuery' => '' ), ); } RECIPE MODEL class Recipe extends AppModel { var $name = 'Recipe'; //The Associations below have been created with all possible keys, those that are not needed can be removed var $hasOne = array( 'Category' => array('className' => 'Category', 'foreignKey' => 'id', 'conditions' => '', 'fields' => '', 'order' => '', 'dependent' => '' ), ); } Do I have the concept or am I missing something? I also had bake setup the controllers and views for me. When I view a recipe say with category_id = 2, category 1 shows up under views. Also should the add/edit view generated by scaffold have the categories as a select box with the categories in it? Right now I have a text box which makes me think that I don't have the associates set up correctly. Thanks Mark --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---