Re: Validating HABTM
You should check this: http://bakery.cakephp.org/articles/nachopitt/2010/07/01/habtm-validatable-behavior On 15 jun, 08:24, Shaz wrote: > I haven't actually made models for the Join table - I don't think you > need to for a HABTM relationship > > On Jun 15, 1:41 pm, Rob Maurer wrote: > > > > > > > > > Interesting. What would happen if you put the validation in the model > > for the join table? > > > On Jun 14, 3:17 pm, Shaz wrote: > > > > I can - but in that arises another situation: > > > > I also have Location HABT Language - and I don't want any restrictions > > > there. So a location can have more than 3 or no languages associated > > > with it. > > > > So if place the above $validate in language model, both users and > > > locations will need to pass that validation; where I only want the > > > users to... > > > > Thanks! > > > > On Jun 14, 8:14 pm, hunny wrote: > > > > > Write the Validation Rule in Language Model instead of User Model > > > > > On Jun 14, 9:56 pm, Shaz wrote: > > > > > > I have User HABTM Language, and i want to ensure during a User add / > > > > > edit they choose a minimum of one language, upto a maximum of 3. In > > > > > the user model, for $validate I've tried: > > > > > > 'Language' => array( > > > > > 'multiple' => array( > > > > > 'rule' => array('multiple', > > > > > array('min' => 1, 'max' => 3)), > > > > > 'message' => 'Please select a tleast > > > > > 1 langiage upto a maximum of > > > > > 3' > > > > > ), > > > > > ), > > > > > > And in the add/edit form i have $this->Form->input('Language'); which > > > > > doesn't actually validate. > > > > > > It does work if I use language_id instead of Language (both in the > > > > > form on the add/edit pages and in the model $validate) - but then it > > > > > doesn't save any data in the join table. > > > > > > Any advice on getting the above to validate, or save habtm when using > > > > > "_id". -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. 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
Re: Add/Edit not working when joined two tables using hasOne.
Paste your add/edit view code please. On 19 abr, 15:33, jackgoh wrote: > Hi, > > Model: > // Stock model > //== > class Stock extends AppModel > { > var $name = 'Stocks'; > var $belongsTo = array( > 'Category' => array( 'className' => 'Category', > 'conditions' => array('Category.id = category_id'), > ) > ); > > var $hasOne = array('StockDetail' => array( 'className' => > 'StockDetail' )); > > } > > // StockDetail model > //== > class StockDetail extends AppModel > { > var $name = 'Stock_details'; > var $belongsTo = array( > 'Stock' => array( 'className' => > 'Stock', > 'foreignKey' => '', > 'conditions' => array('Stock.id = stock_id') > ) > ); > > } > > // Stock Controller > //== > function edit($id = null) { > $this->Stock->id = $id; > $catergorys = $this->Stock->Category->find('list', > array( 'fields' => > array('id','combined_shortname'), > 'conditions' => array('status' > => 'A') ) > ); > $this->set(compact(catergorys)); > if (empty($this->data)) { > $this->data = $this->Stock->find( array('Stock.id' => > $this->Stock->id )); > > } else { > $this->Stock->save($this->data['Stock']); > $this->StockDetail->save($this->data['StockDetail']); > $this->Session->setFlash('Your post has been > updated.'); > // add redirect here... > } > } > > Everything goes fine to display the data in Viewe, but it is not > working when update the record, the data in StockDetail table is not > updated, the record is ONLY updated in Stock table. > > I tried saveAll(), but it insert a new record for Stock Only. I tried > $this->StockDetail->save($this->data)... > > Thanks for helping me. > > Best regards. -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. 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
Re: Simple "join => array('Post')" creates invalid SQL command! --psybear
Try using $this->recursive = -1; before executing the finder. On 13 dic, 05:33, Joshua Muheim wrote: > It's getting better... It now returns the correct count with the following > code: > > $this->find( > 'count', array( > 'joins' => array( > array( > 'table' => 'posts', > 'type' => 'left', > 'conditions' => array( > 'MetaTag.post_id' => 'Post.id' > ) > ) > ), > 'conditions' => array( > 'MetaTag.id' => $this->id(), > 'Post.user_id' => $user->id(), > ) > ) > ) > > Still, its produced SQL statement seems a bit strange... it creates 2 > joins! Both are called "posts", but the 2nd is aliased "Post". > > Query: SELECT COUNT(*) AS `count` FROM `meta_tags` AS `MetaTag` left > JOIN posts ON (`MetaTag`.`post_id` = 'Post.id') LEFT JOIN `posts` AS > `Post` ON (`MetaTag`.`post_id` = `Post`.`id`) WHERE `MetaTag`.`id` = > '1601' AND `Post`.`user_id` = 1103 > > Is this normal? What's it for? > > On Mon, Dec 13, 2010 at 10:01 AM, Jeremy Burns | Class Outfit > > wrote: > > Change the alias in joins array, else it will appear in the SQL twice. > > > Jeremy Burns > > Class Outfit > > > jeremybu...@classoutfit.com > >http://www.classoutfit.com > > > On 13 Dec 2010, at 08:50, Joshua Muheim wrote: > > >> Still doesn't work: > > >> debug( > >> $this->find( > >> 'count', array( > >> 'joins' => array( > >> array( > >> 'alias' => 'Post', > >> 'table' => 'posts', > >> 'type' => 'left', > >> 'conditions' => array( > >> 'MetaTag.id' => $this->id > >> ) > >> ) > >> ) > >> ) > >> ) > >> ); > > >> results in > > >> Warning (512): SQL Error: 1066: Not unique table/alias: 'Post' > >> [CORE/cake/libs/model/datasources/dbo_source.php, line 684] > >> Query: SELECT COUNT(*) AS `count` FROM `meta_tags` AS `MetaTag` left > >> JOIN posts AS `Post` ON (`MetaTag`.`id` = '1601') LEFT JOIN `posts` AS > >> `Post` ON (`MetaTag`.`post_id` = `Post`.`id`) WHERE 1 = 1 > > >> I'm using CakePHP 1.3.6... Anyone of you guys successfully used the > >> joins feature? Seems to be rather complicated to me... ;-) > > >> On Mon, Dec 13, 2010 at 6:01 AM, eugenioc...@hotmail.com > >> wrote: > >>> try using > >>> 'MetaTag.id' => $this->id > > >>> instead of > 'MetaTag.id' => $this->id() > > >>> the correct find sentence will be; > > >>> $this->find( > >>> 'count', > >>> array( > >>> 'joins' => array( > >>> array( > >>> 'alias' => 'Post', > >>> 'table' => 'posts', > >>> 'type' => 'left' > >>> 'conditions' => array( > >>> 'MetaTag.id' => $this->id > >>> ) > >>> ) > >>> ) > >>> ) > >>> ); > > >>> On 12 dic, 21:37, McBuck DGAF wrote: > How about: > > $this->find( > 'count', > array( > 'joins' => array( > array( > 'alias' => 'Post', > 'table' => 'posts', > 'type' => 'left' > 'conditions' => array( > 'MetaTag.id' => $this->id() > ) > ) > ) > ) > ); > > On Dec 11, 6:57 pm, Joshua Muheim wrote: > > > Thanks, but while hoping that DRY and convention over configuration > > would apply here too, adding these informations still results in an > > invalid SQL statement: > > > SELECT COUNT(*) AS `count` FROM `meta_tags` AS `MetaTag` Post posts > > left LEFT JOIN `posts` AS `Post` ON (`MetaTag`.`post_id` = > > `Post`.`id`) WHERE `MetaTag`.`id` = 1601 AND `Post`.`user_id` = 1103 > > > On Sun, Dec 12, 2010 at 12:34 AM, cricket > > wrote: > >> On Sat, Dec 11, 2010 at 2:27 PM, psybear83 wrote: > >>> Hey everybody > > >>> class MetaTag extends AppModel { > >>> var $name = 'MetaTag'; > >>> var $displayField = 'name'; > > >>> function allowsAdd(&$user, $options) { > >>> $this->find('count', array('joins' => array('Post'), > >>> 'conditions' => array('MetaTag.id' => $this->id(; > >>> } > >>> } > > >>> This simple JOIN gives me a wrong SQL command: > > >>> SELECT COUNT(*) AS `count` FROM `meta_tags` AS `MetaTag` Post LEFT > >>> JOIN `posts` AS `Post` ON (`MetaTag`.`post_id` = `Post`.`id`) WHERE > >>> `MetaTag`.`i
Re: Acl and bindNode
Hi Soichi. I think the problem seems to be that you are using the Acl Component instead of the Acl Behavior. The code will be only executed if your User model has the ACL Behavior attached to it. The ACL Component has another purporse. On 7 dic, 14:03, Soichi Hayashi wrote: > Hi. I started using CakePHP 3 days ago, and I am using Cake 1.3.6. I > am having the same problem reported in this thread. > > I have following in my User model > > //make ACL group only (http://book.cakephp.org/view/1547/Acts-As-a- > Requester) > function bindNode($user) { > return array('Group' => array('id' => $user['User'] > ['group_id'])); > } > > When I add a new user, it's adding a new User model record in aros > table. I've patched db_acl as parallel32 suggests, but it's still > adding User model records when I add new users. > > I've also noticed that bindNode() doesn't seem to be called at all > (I've put exit in it, but it doesn't seem to affect the behavior of > the app at all). I have following in my app_controller.php > > var $components = array('Acl'); > > Is there something else that I need to do to make group-only > authorization work? > > Soichi > > On Nov 27, 8:55 am, parallel32 wrote: > > > A very minor change to the core, but you're right nutesco it would > > break upgrades. So far the fix is holding steady on my deployments so > > I'm going to submit it as a bug and perhaps they can permanently fix > > it for the next release. > > > If anyone has a userland fix that would be even better in case it > > takes a while to fix the core. > > > On Nov 23, 4:38 pm, netusco wrote: > > > > I just had the same problem, it really looks like a bug on cakephp... > > > > It was working when ids of groups where the same as ids of aros, but > > > not working when different. > > > > I agree with parallel 32 but I would prefer not to use his approach as > > > it would break in any upgrading... > > > > Is there anyone who could get a light on this issue? > > > > thanks > > > > On Nov 22, 8:37 pm, Jeremy Burns | Class Outfit > > > > wrote: > > > > See the previous reply in this thread that arrived yesterday - haven't > > > > followed it through yet. > > > > > Jeremy Burns > > > > Class Outfit > > > > > jeremybu...@classoutfit.comhttp://www.classoutfit.com > > > > > On 21 Nov 2010, at 22:49, Rajat wrote: > > > > > > i m also facing this issue. > > > > > did u get any official updates on this? > > > > > > On Nov 4, 1:34 am, Jeremy Burns | Class Outfit > > > > > wrote: > > > > >> I'm still really hoping that someone with some inside knowledge can > > > > >> shed a light on this for me. > > > > > >> Jeremy Burns > > > > >> Class Outfit > > > > > >> jeremybu...@classoutfit.comhttp://www.classoutfit.com > > > > > >> On 1 Nov 2010, at 07:24, Jeremy Burns | Class Outfit wrote:> Because > > > > >> the users table has a group_id on it. > > > > > >>> Jeremy Burns > > > > >>> Class Outfit > > > > > >>> jeremybu...@classoutfit.com > > > > >>>http://www.classoutfit.com > > > > > >>> On 31 Oct 2010, at 14:48, huoxito wrote: > > > > > Guess I dont get your point. > > > > > Users still must de added on Aro's table, otherwise how would your > > > > system know that an user A belongs to group ALFA ? > > > > > On 29 out, 08:23, Jeremy Burns | Class Outfit > > > > wrote: > > > > > Anybody else got any more ideas on this? Anyone using it with > > > > > success? > > > > > > Jeremy Burns > > > > > Class Outfit > > > > > > jeremybu...@classoutfit.com > > > > > (t) +44 (0) 208 123 3822 > > > > > (m) +44 (0) 7973 481949 > > > > > Skype: jeremy_burnshttp://www.classoutfit.com > > > > > > On 27 Oct 2010, at 17:10, Jeremy Burns | Class Outfit wrote: > > > > > >> I wish that were the case, but the guide then gives an example > > > > >> of the aros table, which only includes > > > > >> groups:http://book.cakephp.org/view/1547/Acts-As-a-Requester > > > > > >> Jeremy Burns > > > > >> Class Outfit > > > > > >> jeremybu...@classoutfit.com > > > > >>http://www.classoutfit.com > > > > > >> On 27 Oct 2010, at 13:41, cricket wrote: > > > > > >>> On Tue, Oct 26, 2010 at 4:40 PM, Jeremy Burns > > > > >>> wrote: > > > > According to the online tutorial: > > > > > " > > > > In case we want simplified per-group only permissions, we need > > > > to > > > > implement bindNode() in User model. > > > > Code View > > > > > function bindNode($user) { > > > > return array('Group' => array('id' => > > > > $user['User']['group_id'])); > > > > } > > > > > function bindNode($user) { > > > > return array('Group' => array('id' => $user['User'] > > > > ['group_id'])); > > > > } > > > > > This method will tell ACL to skip checking User Aro's and to > > > > check > > > >
Re: Another HABTM issue : row with same Id getting over-written
Yeah, teknoid has a point. Your relation/association is not supposed to work in that way. Normally, in a non CakePHP enviroment, a joinTable has the 2 foreign keys and they set as the "primary key" column. You don´t have the "id" column that CakePHP expects to have and then the foreign keys... thats why the "uniqueness" of the records. Personally i would change the schema of you database for something like users web_pages (holding the url, title, etc) web_page_types (holding the name of the webpage type) And the associations user hasMany webpages webpage belongsTo user webpage belongsTo webpageType On Oct 3, 6:37 pm, teknoid <[EMAIL PROTECTED]> wrote: > Goes to show I should read more carefully :) > I guess the title of the post made me jump the gun... > > You say "an user has 2 of the same webpage_type" > > Does it mean that in your join table you have something like: ? > user_id | web_page_type_id > - > 7 | 6 > 7 | 6 > > On Oct 3, 6:27 pm, Brenton B <[EMAIL PROTECTED]> wrote: > > > Well, assuming the Docs are correct (and I understand it properly), > > that should only apply to updates ("If true (default value) cake will > > first delete existing relationship records in the foreign keys table > > before inserting new ones, when updating a record. So existing > > associations need to be passed again when updating"). > > > However, in my circumstance, I'm just retrieving information ... > > > Debug SQL shows the (as expected) query of getting all webpages & > > types based on the user_id, and it retrieves all the information > > that's needed; however, by the time I get to the view (where I have a > > `pr()`), I've magically lost one of 'em - well, actually, any > > subsequent webpage_type record that has the same id. > > > Conventions: Yeah, I know those were just there, left over from > > scaffolding, so figured no harm in leaving 'em ... > > > On Oct 3, 3:19 pm, teknoid <[EMAIL PROTECTED]> wrote: > > > > Do you know what 'unique'=>true does? > > > > Btw, there really isn't any need to define default values for your > > > associations if you follow the conventions. > > > > On Oct 3, 6:10 pm, Brenton B <[EMAIL PROTECTED]> wrote: > > > > > Ok, so here's the scenario ... > > > > > A user can have multiple webpages in their account, and when they set > > > > them up, they must choose the type (ex: blog, gallery, etc). So User > > > > HABTM webpage_type ... where users_webpage_types has additional fields > > > > for URL, title, etc. > > > > > The thing I'm running into is upon retrieving: If an user has 2 of the > > > > same webpage_type, it performs the SQL to get 'em all, but once it's > > > > done it's magic, it only has the first record. I'm assuming this is > > > > due to the occurrence of the same webpage_type_id, but still lost ... > > > > > User:: > > > > > var $hasAndBelongsToMany = array( > > > > 'WebpageType' => array('className' => > > > > 'WebpageType', > > > > 'joinTable' => > > > > 'users_webpage_types', > > > > 'foreignKey' => > > > > 'userr_id', > > > > 'associationForeignKey' > > > > => 'webpage_type_id', > > > > 'with' => > > > > 'UsersWebpageType', > > > > 'unique' => true, > > > > ), > > > > > WebpageType:: > > > > > var $hasAndBelongsToMany = array( > > > > 'User' => array('className' => 'User', > > > > 'joinTable' => > > > > 'users_webpage_types', > > > > 'foreignKey' => > > > > 'webpage_type_id', > > > > 'associationForeignKey' > > > > => 'user_id', > > > > 'with' => > > > > 'UsersWebpageType', > > > > 'unique' => true, > > > > > UsersWebpageType:: > > > > > var $belongsTo = array( > > > > 'User' => array('className' => 'User', > > > > > > > > 'foreignKey' => 'user_id', > > > > > > > > 'conditions' => '', > > > > > > > > 'fields' => '', > > > > 'order' > > > > => '' > > > > ), > > > > 'WebpageType' => array('className' => > > > > 'WebpageType', > > > > > > > > 'foreignKey' => 'webpage_type_id', > > > >
Re: HABTM - SQL Error 1062 w/ 1.2 RC3
Glad to hear that, I was about to ask information for primary keys or maybe a unique index including both foreign keys. On Oct 4, 12:25 am, Keith <[EMAIL PROTECTED]> wrote: > Nevermind...lol too late to be coding... > > For some reason the user_id column in the departments_users table had > been set as a primary key. I'm not exactly sure why, but who knows > maybe I totally bailed and set a primary key flag somewhere along the > line. > > Everything is working though. > > On 4 Oct, 01:12, Keith <[EMAIL PROTECTED]> wrote: > > > I have a situation where I have a user model & a department model. > > > MODEL - User.php > > > var $hasAndBelongsToMany = array( > > 'Department' => array('className' => 'Department', > > 'joinTable' => > > 'departments_users', > > 'foreignKey' => 'user_id', > > 'associationForeignKey' => > > 'department_id', > > 'unique' => true, > > 'conditions' => '', > > 'fields' => '', > > 'order' => '', > > 'limit' => '', > > 'offset' => '', > > 'finderQuery' => '', > > 'deleteQuery' => '', > > 'insertQuery' => '' > > ) > > ); > > > MODEL - department.php > > > var $hasAndBelongsToMany = array( > > 'User' => array('className' => 'User', > > 'joinTable' => > > 'departments_users', > > 'foreignKey' => > > 'department_id', > > 'associationForeignKey' => > > 'user_id', > > 'unique' => true, > > 'conditions' => '', > > 'fields' => '', > > 'order' => '', > > 'limit' => '', > > 'offset' => '', > > 'finderQuery' => '', > > 'deleteQuery' => '', > > 'insertQuery' => '' > > ) > > ); > > > So...my problem is this: > > > I baked my application's controllers, views, and models via the > > console and they are still the defaults. > > > I currently have 2 users & 2 departments in the database. > > > Whenever I associate a user with a single department (doesn't matter > > which one) everything works fine. > > > Whenever I associate a user with both departments I get the following > > error: > > > Warning (512): SQL Error: 1062: Duplicate entry '2' for key 1 [CORE/ > > cake/libs/model/datasources/dbo_source.php, line 521] > > > Query: INSERT INTO `departments_users` (`user_id`,`department_id`) > > VALUES (2,'1'), (2,'2') > > > Any help would be greatly appreciated. This project was created > > exclusively with the 1.2 RC3 so it wasn't an upgrade or anything like > > that from RC2 or before. --~--~-~--~~~---~--~~ 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: What is the "CakePHP way" to use data returned from the model?
So.. can you "query" an unrelated model from any model with the query model? On Sep 26, 11:01 am, alex_c <[EMAIL PROTECTED]> wrote: > Thanks, that is extremely helpful, and makes a lot of sense! > > >Querying "pictures AS > > Picture" will take you one step towards what is returned from Cake's > > find-methods > > That helps a lot. I guess I had assumed that since I was using > $this->Picture->query, Cake was aware that the model should be Picture - but > > on second thought, it has no way of knowing that the query will > actually return a Picture. > > Thank you for the helpful answer, it clears up a lot of things for me. > > Alex > > On Sep 26, 10:15 am, "[EMAIL PROTECTED]" > > <[EMAIL PROTECTED]> wrote: > > The Model is quite a bit different in CakePHP compared to Rails. > > Since all data is returned as an array structure (and not objects) it > > is "dead" data and not "live" objects. It has to be laid out for you > > in advance. > > > query vs. find > > query is pretty much a wrapper for straight SQL queries. Since you > > query "pictures" that is what you get back. Querying "pictures AS > > Picture" will take you one step towards what is returned from Cake's > > find-methods. Using find you are asking Cake to find data for Models. > > Using qurey you are only using Cakes dbo layer to ask sql queries. > > > find('first') vs. find('all') > > When asking for a single record you will get back an array with the > > model's name as a key to access its data. $data['Picture']... > > When asking for multiple records you will get back an numeric array. > > Each one of the elements in that array will be identical to what the > > single record returned. $data[2]['Picture']... > > > Why the ['Picture']? > > My take on why this structure was chosen is that is allows the same > > view-elements to render from many different find operations. If > > Article hasMany Picture you would access the picture data the same > > from Article as from Picture directly. > > Picture->find returns an array with a Picture key > > Article->find returns an array with both Article and Picture keys. > > A view element used to show pictures anywhere in the application would > > never need to know that the pictures were found as related data or > > not. The same goes for the form helper and any other code used to > > manipulate data. > > > At least that is one possible reason. I was not in the room when they > > came up with it ;) > > > I hope that was helpful. Just remember that Cake is (or once was) > > similar to Rails in an overall perspective on things but not really in > > the details. > > > On Sep 26, 3:49 am, alex_c <[EMAIL PROTECTED]> wrote: > > > > Hi all, > > > > I am new to CakePHP. I've used both PHP (with no frameworks) and Ruby > > > on Rails in the past, and decided that learning a PHP framework might > > > make PHP projects a lot more pleasant. I chose CakePHP because I'm > > > familiar with Rails - so far it's great, but I do have to wrap my head > > > around the differences. > > > > I'm a bit unsure on what is the "CakePHP way" to use data returned > > > from the model. To keep things simple, let's say I have a model > > > Picture, with only one field, id. > > > > What's throwing me off is that the data returned doesn't always seem > > > to follow a consistent format. For example, > > > > $this->Picture->findById("1") > > > > will return > > > > Array > > > ( > > > [Picture] => Array > > > ( > > > [id] => 1 > > > ) > > > ) > > > > but > > > > $this->Picture->query("SELECT * FROM pictures WHERE id=1") > > > > will return > > > > Array > > > ( > > > [0] => Array > > > ( > > > [pictures] => Array > > > ( > > > [id] => 1 > > > ) > > > ) > > > ) > > > > It feels a bit odd to have to write, for example, $pic["Picture"] > > > ["id"] everywhere, rather than $pic["id], but I can live with that. > > > > What's really throwing me off is $pic["Picture"]["id"] versus > > > $pic["pictures"]["id"]. Having to account for that every time I > > > either read or use data seems... well... it really doesn't feel right. > > > > So, am I missing anything? Am I supposed to massage the data returned > > > from Find and Query methods in the controller? How do you guys use it > > > in your views and helpers, to keep things as simple and consistent as > > > possible? > > > > I'm using 1.2.0.7296-RC2. > > > > Thanks for any help! > > > > Alex --~--~-~--~~~---~--~~ 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: send email using SMTP - From name got replaced
I dont know a workaround for this problem. It is a server side issue. On Sep 25, 10:36 pm, Musa <[EMAIL PROTECTED]> wrote: > is there any way not to add gmail account address??? > > Musa > > On Fri, Sep 26, 2008 at 9:22 AM, nachopitt <[EMAIL PROTECTED]> wrote: > > > Thats correct. Gmail replaces the From field with the account address > > the SMTP mail server is using for authentication. > > > On Sep 25, 4:23 pm, "[EMAIL PROTECTED]" > > <[EMAIL PROTECTED]> wrote: > > > Hi there, > > > > I am using PHPMailer and gmail SMTP service to send email, and > > > blocked by the issue - From name got replaced by gmail address. > > > > I specified From and FromName while sending the email. In debugging, > > > the mail header includes the correct FromName and From address). > > > gmail succeeded to send this email. After check the email, the From > > > address is not what I specified. It is shown as the SMTP gmail > > > account. > > > > I am not sure if it is by design with gmail SMTP (I heard that gmail > > > replace it with gmail account). Does anyone know how to figure it out? > > > I'd appreciate it very much. > > > > Thanks, > > > Bo --~--~-~--~~~---~--~~ 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: send email using SMTP - From name got replaced
Thats correct. Gmail replaces the From field with the account address the SMTP mail server is using for authentication. On Sep 25, 4:23 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > Hi there, > > I am using PHPMailer and gmail SMTP service to send email, and > blocked by the issue - From name got replaced by gmail address. > > I specified From and FromName while sending the email. In debugging, > the mail header includes the correct FromName and From address). > gmail succeeded to send this email. After check the email, the From > address is not what I specified. It is shown as the SMTP gmail > account. > > I am not sure if it is by design with gmail SMTP (I heard that gmail > replace it with gmail account). Does anyone know how to figure it out? > I'd appreciate it very much. > > Thanks, > Bo --~--~-~--~~~---~--~~ 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: HasManyAndBelongsToMany Problem on the link table Cake1.2
Are you trying to add a new but existing pair of (attendance, member) to the join Table? The data in the join table must be unique, and there is a key in the association array for the purpose of having the pair of the 2 foreign keys unique in the table (like a composite key). Maybe you are trying to add an existing pair of foreign Keys, and CakePHP is deleting the past one to have the nwe one. On Sep 23, 9:39 pm, Andre <[EMAIL PROTECTED]> wrote: > I'm doing a Member, Attendance project for church with the following > schema below: > And I'm able to save from both end member, and attendance, but the how > do I deal with attendances_members.offering on the link table. > I'm able to show it in the view and save, but if I edit attendance, > the link record is recreated and the previously populated > attendances_members.offering is gone. > > Please help. > > create table members ( > id int not null auto_increment primary key, > first_name varchar(40) not null, > last_name varchar(40) not null, > date_of_birth date > ); > > create table attendances ( > id int not null auto_increment primary key, > attend_date date not null > ); > > create table attendances_members ( > id int not null auto_increment primary key, > member_id int not null, > attendance_id int not null, > offering decimal(6,2), > primary key (id) > ); > > Model: > attendance.php > /* > * Created on Sep 20, 2008 > * By: susantan > * File: attendance.php > * > */ > class Attendance extends AppModel { > var $name = 'Attendance'; > var $hasAndBelongsToMany = array('Member'); > } > ?> > > member.php: > > class Member extends AppModel { > var $name = 'Member'; > var $hasAndBelongsToMany = array('Attendance'); > > } > ?> > Controllers: > attendances_controller.php: > class AttendancesController extends AppController { > > var $name = 'Attendances'; > var $helpers = array('Html', 'Form'); > > function add() { > if (!empty($this->data)) { > $this->Attendance->create(); > if ($this->Attendance->save($this->data)) { > $this->Session->setFlash(__('The Attendance > has been saved', > true)); > $this->redirect(array('action'=>'index')); > } else { > $this->Session->setFlash(__('The Attendance > could not be saved. > Please, try again.', true)); > } > } > $members = $this->Attendance->Member- > > >find('list',array('fields'=>'Member.first_name')); > > $this->set(compact('members')); > } > ?> > > members_controller.php: > class MembersController extends AppController { > > var $name = 'Members'; > var $helpers = array('Html', 'Form'); > > function add() { > if (!empty($this->data)) { > $this->Member->create(); > if ($this->Member->save($this->data)) { > $this->Session->setFlash(__('The Member has > been saved', true)); > $this->redirect(array('action'=>'index')); > } else { > $this->Session->setFlash(__('The Member could > not be saved. > Please, try again.', true)); > } > } > $attendances = $this->Member->Attendance->find('list'); > $this->set(compact('attendances')); > } > > views: > attendances/add.ctp: > > create('Attendance');?> > > > echo $form->input('attend_date'); > echo > $form->input('Member',array('type'=>'select','multiple'=>'checkbox')); > > ?> > > end('Submit');?> > --~--~-~--~~~---~--~~ 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: problem in auth component, please help
I know that AppController::beforeFiler() is a better place to put the Auth Component configuration to share the same configuration between all controllers and have all protected by Auth. On Sep 23, 2:52 pm, "Golam Kibria" <[EMAIL PROTECTED]> wrote: > hello i have tried authcomponent but i dont know why it is not working for me. > > i have two controller Doctors and Patients. Login methods are in > Doctors controller. > > After hit the login form, the login form reappears with no flash/auth message. > > Doctors Controller code > > var $name = 'Doctors'; > var $components = array('Auth'); > > function beforeFilter(){ > $this->Auth->userModel = 'Doctor'; > $this->Auth->fields = array('username'=>'email', > 'password'=>'password'); > $this->Auth->loginAction = array('controller' => 'Doctors', > 'action' => 'login'); > $this->Auth->loginRedirect = array('controller' => 'Patients', > 'action' => 'index'); > $this->Auth->allow('login'); > $this->Auth->authorize = 'controller'; > $this->Auth->userScope = array('Doctor.status'=>1); > } > > function isAuthorized() { > return true; > } > function login(){ > > } > > function logout(){ > $this->Session->setFlash('You Have been Logged Out.'); > $this->redirect($this->Auth->logout()); > > } > > Patients Controller code > > var $name = 'Patients'; > var $components = array('Auth'); > > function beforeFilter(){ > $this->Auth->userModel = 'Doctor'; > $this->Auth->fields = array('username'=>'email', > 'password'=>'password'); > $this->Auth->loginAction = array('controller' => 'Doctors', > 'action' => 'login'); > $this->Auth->loginRedirect = array('controller' => 'Patients', > 'action' => 'index'); > $this->Auth->allow('login'); > $this->Auth->authorize = 'controller'; > $this->Auth->userScope = array('Doctor.status'=>1); > } > > function isAuthorized() { > return true; > } > > anyone please help me > > 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: changing data in the hasAndBelongsToMany tables
Hey thanks a lot for this information. Do you know how to handle this when you have multiple People to be attached to the same Match, along with the roles? On Sep 16, 12:08 pm, Dérico Filho <[EMAIL PROTECTED]> wrote: > Just solved it: > > $this->Match->save( > Array( > "Match" => Array( > "id" => $match_id > ), > "Person" => Array( > "Person" => Array( > Array( > "person_id" => > $main_referee_id, > "role" => > 'main_referee' > ) > ) > ) > ) > ); > > On Sep 16, 12:57 pm, Dérico Filho <[EMAIL PROTECTED]> wrote: > > > Hi, > > > I have two tables: > > > matches > > people > > > linked together by: > > > matches_people > > > Well, on the matches_people table there are other fields but match_id > > and person_id, for instance: role, a enum type field. > > > The question is how do I save data into matches_people in way I can > > also update the role field? > > > I've tried: > > $this->Match->save( > > Array( > > "Match" => Array( "id" => $match_id > > ), > > "Person" => Array( "id" => > > $main_referee_id ), > > "MatchPerson" => Array( "role" => > > "main_referee" ) > > ) > > ); > > > But it did not work out, how do I do it? > > > 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: Help with models?
Isn't just only a 'belongs to' association? 'Product' belongsTo 'Category'? On Sep 11, 9:31 pm, "David C. Zentgraf" <[EMAIL PROTECTED]> wrote: > You're doing it exactly the way you described > it:http://book.cakephp.org/view/81/belongsTohttp://book.cakephp.org/view/82/hasMany > > On 12 Sep 2008, at 07:41, VitillO wrote: > > > > > This is the case, i have a tables "products", "categories". Normally i > > would link a category to a product using product.category_id, and > > since a category can be assigned to many products i dont have a > > product_id in the categories table. So, how can i make this > > relationship between the 2 without using a HABTM table, because lets > > say i want to link a product just to 1 category, not many categories. > > > I will appreciate a lot any help with this! Thank you --~--~-~--~~~---~--~~ 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: Two foreignKey belongsTo same Model
You should name both of your associations with different names. For example: Transaction model : var $belongsTo = array( 'User_created' => array( 'className' => 'User', 'foreignKey' => 'created_id' ), 'User_modified' => array( 'className' => 'User', 'foreignKey' => 'modified_id' ) ); User model : var $hasMany = array( 'Transaction_created' => array( 'className' => 'Transaction', 'foreignKey' => 'created_id' ), 'Transaction_modified' => array( 'className' => 'Transaction', 'foreignKey' => 'modified_id' ) ); Hope this helps. On Sep 11, 4:09 am, Sen <[EMAIL PROTECTED]> wrote: > Hi all, i need some help. > > I have two table, let's say User and Transaction with this kind of > relation : > > User has some common fields : > id > username > password > > Transaction : > created_id is a foreign key to model User (id) > modified_id is a foreign key to model User (id) too > > how do define the model relation with this kind of situation ? > > i put it in this way but it does not work. > > User model : > > var $hasMany = array( > 'Transaction' => array( > 'className' => 'Transaction', > 'foreignKey' => 'created_id' > ), > > 'Transaction' => array( > 'className' => 'Transaction', > 'foreignKey' => 'modified_id' > ) > ); > > Transaction model : > > var $belongsTo = array( > 'User' => array( > 'className' => 'User', > 'foreignKey' => 'created_id' > ), > > 'User' => array( > 'className' => 'User', > 'foreignKey' => 'modified_id' > ) > ); > > Tks. --~--~-~--~~~---~--~~ 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: Auth - can't login
I think he wasn't following the convention to have a table named 'Users' with at least to fields named 'username' and 'password'. On Sep 10, 4:28 pm, Klesus <[EMAIL PROTECTED]> wrote: > Hi, > > Can you tell us how you solve the problem ? I think I have exactly > the same : > > SQL Error: 1054: Unknown column 'User.statu_id' in 'on clause' [CORE/ > cake/libs/model/datasources/dbo_source.php, line 512] > It is real that User.statu_id does not exist. But why CakePhp build > broken query ? > > Thanks for your help. > > Seb > > On 31 ago, 08:36, Jeroen <[EMAIL PROTECTED]> wrote: > > > No I didn't have. > > Thanks! Problem solved! > > What a stupid mistake > > > On 31 aug, 02:35, "Dardo Sordi Bogado" <[EMAIL PROTECTED]> wrote: > > > > Has your user table a field called `username` ? > > > > On Sat, Aug 30, 2008 at 6:00 PM, Jeroen <[EMAIL PROTECTED]> wrote: > > > > > I followed the instructions > > > > onhttp://book.cakephp.org/view/172/authentication > > > > to create a login. The problem is that I get the following error when > > > > I try to login: > > > > SQL Error: 1054: Unknown column 'User.username' in 'where clause' [CORE > > > > \cake\libs\model\datasources\dbo_source.php, line 512] > > > > > Cake (Auth) searches for the wrong table to login, it need to search > > > > for the table Users instead of User. > > > > I'm using Cake version 1.2.0.7296 RC2. > > > > > I use the following code: > > > > class AppController extends Controller { > > > > var $components = array('Auth'); > > > > > function beforeFilter(){ > > > > $this->Auth->loginAction = > > > > array(Configure::read('Routing.admin') => > > > > false, 'controller' => 'users', 'action' => 'login'); > > > > $this->Auth->allow('index','view'); > > > > } > > > > > } > > > > > Login view: > > > > > > > if ($session->check('Message.auth')) $session->flash('auth'); > > > > echo $form->create('User',array('action' => 'login')); > > > > echo $form->input('username'); > > > > echo $form->input('password'); > > > > echo $form->end('Login'); > > > > ?> > > > > > > > > class UsersController extends AppController { > > > > > var $name = 'Users'; > > > > var $helpers = array('Html', 'Form', 'Session' ); > > > > > /** > > > > * The AuthComponent provides the needed functionality > > > > * for login, so you can leave this function blank. > > > > */ > > > > function login() { > > > > } > > > > > function logout() { > > > > $this->redirect($this->Auth->logout()); > > > > } > > > > > } > > > > ?> > > > > > I tried the following things: > > > > 1. echo $form->create('Users',array('action' => 'login')); instead of > > > > echo $form->create('User',array('action' => 'login'));, but then Auth > > > > wopn't do anything at all. Comparing to other views the syntax echo > > > > $form->create('User',array('action' => 'login')); should be the > > > > correct synax. > > > > 2. Searching the Internet if anyone else had the same problem, but I > > > > can't find anyone with the same problem. > > > > > Three questions > > > > 1. Is this a bug of CakePHP 1.2.0.7296 RC2 or am I doing something > > > > wrong? > > > > 2. Is there amnyone else who uses the Auth-component successfully in > > > > version 1.2.0.7296 RC2? > > > > 3. The most important: anyone has a solution or got an idea?? :) > > > > > Thanks, > > > > > Jeroen --~--~-~--~~~---~--~~ 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: Trying to use Auth + Acl...
By looking at your code, I can see that you are defining all of your models to be "controlled". Is that a different way to control your objects, being the models to be the ACOs insted of the pairs 'controllers-actions'? Also, I see that you pretend to have groups inside groups, but you are returning a parent that is supossed to be another group, and you are returning the same group... Is that correct? return array('Group' => array('id' => $data['Group']['id'])); On Sep 10, 10:35 am, avairet <[EMAIL PROTECTED]> wrote: > Ok, nobody answers... > > So, one error I've made is to call AuthComponent before AclComponent > in $components array ! > And another error is to not authorize an action called by a > requestAction()... > > Hope this help! > > On 10 sep, 14:13, avairet <[EMAIL PROTECTED]> wrote: > > > Hi, > > > I'm trying to use Auth Component and Acl Component and Acl Behavior > > like that: > > > 1) App_controller: > > > public $components('Auth','Acl'); > > > public beforeFilter() { > > $this->Auth->userModel = 'User'; > > $this->Auth->fields = array('username' => 'pseudo', 'password' => > > 'password'); > > $this->Auth->loginAction = 'users/login'; > > $this->Auth->loginRedirect = 'profil/mes-infos'; > > $this->Auth->logoutRedirect = '/'; > > $this->Auth->authorize = 'actions'; > > $this->Auth->loginError = __('Identifiant ou mot de passe > > incorrect.', true); > > $this->Auth->authError = __('Vous n\'avez pas accès à cette page. > > Veuillez vous identifier.', true); > > $this->Auth->autoRedirect = true; > > > } > > > 2) App_model: > > > public $actsAs = array ( > > 'Acl' => array('type' => 'controlled'), > > 'Containable' => array(true,'notices' => true) > > ); > > > public function parentNode() { > > return null; > > > } > > > 3) User model: > > > public $actsAs = array ( > > 'Acl' => array('type'=>'requester'), > > 'Containable' => array(true,'notices' => true) > > > } > > > public function parentNode() { > > if (!$this->id && empty($this->data)) { > > return null; > > } > > $data = $this->data; > > if (empty($this->data)) { > > $data = $this->read(); > > } > > if (!$data['User']['group_id']) { > > return null; > > } else { > > return array('Group' => array('id' => $data['User'] > > ['group_id'])); > > } > > > } > > > 4) Group model: > > > public $actsAs = array ( > > 'Acl' => array('type'=>'requester'), > > 'Containable' => array(true,'notices' => true) > > ); > > > public function parentNode() { > > if (!$this->id && empty($this->data)) { > > return null; > > } > > $data = $this->data; > > if (empty($this->data)) { > > $data = $this->read(); > > } > > if (!$data['Group']['id']) { > > return null; > > } else { > > return array('Group' => array('id' => $data['Group']['id'])); > > } > > > } > > > 5) ExpertsController: > > > public function beforeFilter() { > > parent::beforeFilter(); > > $this->Auth->allowedActions = array('index'); > > > } > > > public function index() {} > > > So when I request "http://www.mywebsite/experts";, I can't access to > > index() view, there is a infinite loop??! > > And if I request a protected action (e.g. "http://www.mywebsite/ > > experts/add", I'm never redirected to login page, there is a infinite > > loop too??! > > > Do I something wrong in this basic usage of Auth + Acl? > > > Thank's by advance for any suggestions! > > > BR --~--~-~--~~~---~--~~ 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: Why is Model::data set to false after Model::save() ?
Maybe you could overload the afterSave callback (method) of the model you are trying to make changes to its data. On Sep 6, 1:30 pm, MarcS <[EMAIL PROTECTED]> wrote: > Hi, > > I have trouble understanding why the Model::data array is being set to > false after saving the model. > Many times I need to save the model (for example because I need the > insert Id to work with a associated model) but after that I still need > to make changes the Model's data. > > I find myself doing something like > $save_data = $this->Model->save(); > $save_data['Model']['id'] = $this->id; > $this->Model->create($save_data) > > all the time. > > Is there a good way to get around that? > Am I doing something very stupid here? > > thanks, > Marc --~--~-~--~~~---~--~~ 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: HABTM with formHelper
Im facing exactly the same problem right now. Im just curious about the structure the array has to have to be able to use $this->Model1- >save() inside the controller and save the HABTM record in the jointable. I have students and subjetcs. The association is many to many. I cannot create a student and a subject at the same time I create a subject, or viceversa. The process is to have both models filled with records, and then, enroll a student in a subject. I dont know how to setup the views (in the controller could be an 'enroll' action in the students controller, or maybe in subjects controller) with the form to submit the relation and save the HABTM record. Thanks in advance. On Aug 12, 11:41 am, teknoid <[EMAIL PROTECTED]> wrote: > $this->Paysite->Niche->find('list'), since you need the Niche.id and > Niche.name > > On Aug 12, 5:36 am, tekomp <[EMAIL PROTECTED]> wrote: > > > Hi, > > > I have a basicHABTMrelationship. Join table is "niches_paysites". > > I'm setting up CRUD for "paysites", but can't get the form helper to > > populate the "select" input box with the names from the "niches" > > table. It's creating the select input box, but there are no > > options. It works fine when scaffolding though. > > > I've tried many things in the paysite view, including: > > > $form->input('Niche') > > $form->input('Niche/Niche') > > > I also tried with a number of things in the paysite controller, but to > > no avail: > > > $this->set('niches', $this->Paysite->NichesPaysite->find('list', > > array('Niche.name'))); > > $this->set('niches', $this->NichesPaysites->find('list', > > array('Niches.name'))); > > > I'm not trying to create any new niches on the fly, I just want to > > create associations withexistingniches. Any ideas? --~--~-~--~~~---~--~~ 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: HABTM cascading delete
Ok, I understand your point, but that would lend you to the possibility of have a single address, being of a seller or a client, to be owned by a client AND by a seller any number of times, and I dont think you want to share an address that way. I can think in a possible solution, by having a parent table for both client and seller tables, for grouping purposes. For example: People --- id personType_id Client --- id people_id Seller --- id people_id PersonTypes --- id name Addresses --- id person_id and your associations should be: Person hasMany address Person hasOne client Person hasOne seller Person belongsTo PersonType Client belongsTo People Seller belongsTo People PersonType hasMany Person Address belongsTo People In that way, you're handling both clients and sellers in just one table, the same way you are handling the address table. Hope this helps. On Aug 21, 5:24 pm, Marcello <[EMAIL PROTECTED]> wrote: > that's possible, although its a little troublesome > > i mean, i only gave an example of why im usingHABTM > > the whole system is using only a address table, for the purpose of > maintenance > > if im intending to change something about my address, that would be > much more clear to have only one table/controller/model to handle that > > that's my focus right now, make a system that will give less problems > on maintence, specially because i got more than one client for this > system, so it may have some minor changes that would be awfully sad to > make in many tables > > english isnt my native language to, so no worries ;) > > thanks for all the replys > > On 20 ago, 20:24, nachopitt <[EMAIL PROTECTED]> wrote: > > > Right, i forgot to tell you that. I prefer to let the RDBMS handle > > this, instead of having to write more code in the app. But changing > > from MyISAM to InnoDB can have its drawbacks. > > > Anyway, Marcello I can see by looking at your model that you pretend > > to have both client and seller addresses in one table named Addresses, > > and thats why I suppose you are looking after aHABTMassociation. > > However, you can eliminate this association and have a pair of two > > hasMany and their respective belongsTo associations if you split the > > actual address table in two more being client_addresses and > > seller_addresses. > > > I hope I was clear enough, if not please correct me. > > > Sorry about my english, it's not my native language. > > > On Aug 20, 4:24 pm, Joel Perras <[EMAIL PROTECTED]> wrote: > > > > That will only work if your database engine supports foreign key > > > constraints, such as MySQL InnoDB. The default MySQL MyISAM engine > > > does not support any type of referential integrity; you can set the > > > FOREIGN KEY/REFERENCES attributes, but they will be ignored. > > > > Other database implementations may also be lacking foreign key > > > constraints, but my experience is localized to PostgreSQL and MySQL. > > > > It's probably worth opening up a ticket concerning your issue, since > > > one would expect that the default behaviour for 'dependent' would > > > allow the deletion of the associated entry in the join table, > > > effectively unlinking the two model records in question. I agree with > > > Dave, however, in that in most cases you would not want to delete the > > > associated records in aHABTMrelationship (as opposed to the entry in > > > the join table) for obvious reasons. > > > > -Joel. > > > > On Aug 20, 5:12 pm, Marcello <[EMAIL PROTECTED]> wrote: > > > > > im a little new to referential integrity in the database directly, > > > > could you enligthen me? > > > > > i got 5 tables > > > > > Clients AddressClient Addresses > > > > Sellers AddressSeller > > > > > what i need is, when i delete a client or a seller, it should also > > > > delete his addresses, BUT when i delete a address the client or seller > > > > must remain untouched > > > > > On 20 ago, 12:45, nachopitt <[EMAIL PROTECTED]> wrote: > > > > > > Why don't you just do it the way its suppossed to be? By adding > > > > > referential integrity to the database. For example: > > > > > > CREATE TABLE / ALTER TABLE ... > > > > > ... > > > > > FOREIGN KEY (foreignTableName_id) REFERENCES foreignTableName ON > > > > > DELETE CASCADE; > > > > > > On Aug 20, 9:2
Re: HABTM cascading delete
Right, i forgot to tell you that. I prefer to let the RDBMS handle this, instead of having to write more code in the app. But changing from MyISAM to InnoDB can have its drawbacks. Anyway, Marcello I can see by looking at your model that you pretend to have both client and seller addresses in one table named Addresses, and thats why I suppose you are looking after a HABTM association. However, you can eliminate this association and have a pair of two hasMany and their respective belongsTo associations if you split the actual address table in two more being client_addresses and seller_addresses. I hope I was clear enough, if not please correct me. Sorry about my english, it's not my native language. On Aug 20, 4:24 pm, Joel Perras <[EMAIL PROTECTED]> wrote: > That will only work if your database engine supports foreign key > constraints, such as MySQL InnoDB. The default MySQL MyISAM engine > does not support any type of referential integrity; you can set the > FOREIGN KEY/REFERENCES attributes, but they will be ignored. > > Other database implementations may also be lacking foreign key > constraints, but my experience is localized to PostgreSQL and MySQL. > > It's probably worth opening up a ticket concerning your issue, since > one would expect that the default behaviour for 'dependent' would > allow the deletion of the associated entry in the join table, > effectively unlinking the two model records in question. I agree with > Dave, however, in that in most cases you would not want to delete the > associated records in a HABTM relationship (as opposed to the entry in > the join table) for obvious reasons. > > -Joel. > > On Aug 20, 5:12 pm, Marcello <[EMAIL PROTECTED]> wrote: > > > im a little new to referential integrity in the database directly, > > could you enligthen me? > > > i got 5 tables > > > Clients AddressClient Addresses > > Sellers AddressSeller > > > what i need is, when i delete a client or a seller, it should also > > delete his addresses, BUT when i delete a address the client or seller > > must remain untouched > > > On 20 ago, 12:45, nachopitt <[EMAIL PROTECTED]> wrote: > > > > Why don't you just do it the way its suppossed to be? By adding > > > referential integrity to the database. For example: > > > > CREATE TABLE / ALTER TABLE ... > > > ... > > > FOREIGN KEY (foreignTableName_id) REFERENCES foreignTableName ON > > > DELETE CASCADE; > > > > On Aug 20, 9:21 am, Marcello <[EMAIL PROTECTED]> wrote: > > > > > the main reason for using habtm is because address table is shared > > > > among the whole system > > > > > clients use them, sellers, and so on > > > > and a client can have ANY NUMBER of addresses > > > > the same for seller > > > > so i cant put a foreign key in any of the two tables > > > > > thats why i must use HABTM > > > > > On 20 ago, 10:50, Dave J <[EMAIL PROTECTED]> wrote: > > > > > > Not sure if I made sense in my previous post, but basically this is a > > > > > case in which, if you're in a situation where you need todelete > > > > > dependent records in an HABTM relationship. you might need to > > > > > think if the relationship should be an HABTM one at all... or if a > > > > > simpler hasMany would do the job just as well. > > > > > > On Aug 20, 2:44 pm, Dave J <[EMAIL PROTECTED]> wrote: > > > > > > > I dont think it works for HABTM relations also for the reason > > > > > > that it might be unsafe to do so. By deleting all related records, > > > > > > you > > > > > > might also be deleting records which are referenced to by other > > > > > > entries in the join table. > > > > > > > On Aug 20, 4:03 am, Marcello <[EMAIL PROTECTED]> wrote: > > > > > > > > it does not work (gives no error, but does not remove the > > > > > > > dependent > > > > > > > side) > > > > > > > > On 19 ago, 22:26, Marcello <[EMAIL PROTECTED]> wrote: > > > > > > > > > dependent is exactly what i was looking for > > > > > > > > > thanks! > > > > > > > > > On 19 ago, 22:11, Joel Perras <[EMAIL PROTECTED]> wrote: > > > > > > > > > > Take a look > > > > > > > > > athttp://book.cakephp.org/view/66/models#deleting-data-516 > > > > > > > > >
Re: HABTM cascading delete
Why don't you just do it the way its suppossed to be? By adding referential integrity to the database. For example: CREATE TABLE / ALTER TABLE ... ... FOREIGN KEY (foreignTableName_id) REFERENCES foreignTableName ON DELETE CASCADE; On Aug 20, 9:21 am, Marcello <[EMAIL PROTECTED]> wrote: > the main reason for using habtm is because address table is shared > among the whole system > > clients use them, sellers, and so on > and a client can have ANY NUMBER of addresses > the same for seller > so i cant put a foreign key in any of the two tables > > thats why i must use HABTM > > On 20 ago, 10:50, Dave J <[EMAIL PROTECTED]> wrote: > > > Not sure if I made sense in my previous post, but basically this is a > > case in which, if you're in a situation where you need todelete > > dependent records in an HABTM relationship. you might need to > > think if the relationship should be an HABTM one at all... or if a > > simpler hasMany would do the job just as well. > > > On Aug 20, 2:44 pm, Dave J <[EMAIL PROTECTED]> wrote: > > > > I dont think it works for HABTM relations also for the reason > > > that it might be unsafe to do so. By deleting all related records, you > > > might also be deleting records which are referenced to by other > > > entries in the join table. > > > > On Aug 20, 4:03 am, Marcello <[EMAIL PROTECTED]> wrote: > > > > > it does not work (gives no error, but does not remove the dependent > > > > side) > > > > > On 19 ago, 22:26, Marcello <[EMAIL PROTECTED]> wrote: > > > > > > dependent is exactly what i was looking for > > > > > > thanks! > > > > > > On 19 ago, 22:11, Joel Perras <[EMAIL PROTECTED]> wrote: > > > > > > > Take a look > > > > > > athttp://book.cakephp.org/view/66/models#deleting-data-516 > > > > > > . The 'dependent' parameter can also be set in the model > > > > > > association > > > > > > definition. > > > > > > > Hope that's what you were looking for. > > > > > > -J. > > > > > > > On Aug 19, 8:52 pm, Marcello <[EMAIL PROTECTED]> wrote: > > > > > > > > i got 2 tables linked by a HABTM relationship > > > > > > > > when ideletetable record 1 i want todeletethe relationship with > > > > > > > table and the table 2 record as well > > > > > > > but when ideletefrom table 2 i want to keep table 1 record > > > > > > > > is there any feature in cakephp forcascadingin habtm? --~--~-~--~~~---~--~~ 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: HABTM cascading delete
Why dont you just do it in the way it was supposed to be? By adding referential integrity to the database. For example: FOREIGN KEY (tablename_id) REFERENCES tablename ON DELETE CASCADE On Aug 20, 8:50 am, Dave J <[EMAIL PROTECTED]> wrote: > Not sure if I made sense in my previous post, but basically this is a > case in which, if you're in a situation where you need to delete > dependent records in an HABTM relationship. you might need to > think if the relationship should be an HABTM one at all... or if a > simpler hasMany would do the job just as well. > > On Aug 20, 2:44 pm, Dave J <[EMAIL PROTECTED]> wrote: > > > I dont think it works for HABTM relations also for the reason > > that it might be unsafe to do so. By deleting all related records, you > > might also be deleting records which are referenced to by other > > entries in the join table. > > > On Aug 20, 4:03 am, Marcello <[EMAIL PROTECTED]> wrote: > > > > it does not work (gives no error, but does not remove the dependent > > > side) > > > > On 19 ago, 22:26, Marcello <[EMAIL PROTECTED]> wrote: > > > > > dependent is exactly what i was looking for > > > > > thanks! > > > > > On 19 ago, 22:11, Joel Perras <[EMAIL PROTECTED]> wrote: > > > > > > Take a look athttp://book.cakephp.org/view/66/models#deleting-data-516 > > > > > . The 'dependent' parameter can also be set in the model association > > > > > definition. > > > > > > Hope that's what you were looking for. > > > > > -J. > > > > > > On Aug 19, 8:52 pm, Marcello <[EMAIL PROTECTED]> wrote: > > > > > > > i got 2 tables linked by a HABTM relationship > > > > > > > when i delete table record 1 i want to delete the relationship with > > > > > > table and the table 2 record as well > > > > > > but when i delete from table 2 i want to keep table 1 record > > > > > > > is there any feature in cakephp for cascading in habtm? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---