Re: Media Behaviour not working with hasOne association
Solved this one too :) It was a simple typo in the Cover model class name, so cake couldn't find it and substitued it with AppModel... 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
Media Behaviour not working with hasOne association
I'm using David Perssons Media Behaviour (http://github.com/ davidpersson/media), and i have a small problem. When trying to save a model that has a hasOne association, the associated model is saved, but the behaviour isn't triggered. The association in my model, named Release, is set up like this: var $hasOne = array( 'Cover' => array( 'className' => 'Cover', 'foreignKey' => 'release_id' 'dependent' => true ) ); In the Cover model the Media Behaviours are set up like this: var $actsAs = array('Media.Transfer', 'Media.Generator', 'Media.Coupler'); And in my view i've added/changed this: echo $this->Form->create('Release', array('type' => 'file')); echo $this->Form->input('Cover.file', array('type' => 'file', 'label' => 'Cover')); According to the manual all i need to do now is to call saveAll, but unfortunately it doesn't work correctly. The data sent is structured correctly (according to http://book.cakephp.org/view/1031/Saving-Your-Data), it looks like this: Array ( ... [Release] => Array ( ... ) [Cover] => Array ( [file] => Array ( [name] => test.jpg [type] => image/jpeg [tmp_name] => G:\xampp\tmp\php6E91.tmp [error] => 0 [size] => 178534 ) ) ) and the associated model is saved, ie a record for the Cover model is created, but the behaviours aren't triggered, ie no file is uploaded and the additional dirname and basename fields are empty. Adding some debug output i've found out that the associated model when saved by saveAll isn't using the actual Cover model, instead it uses AppModel where no actsAs is defined. So my question is... what the heck is going on there? ;) Regards 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: 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 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
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 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 -~--~~~~--~~--~--~---
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: question about hasOne association in 1.1
That's a belongsTo association. >From an English-language point of view, I can understand that it doesn't "sound" right. But it is. On Jun 5, 10:15 am, pdt <[EMAIL PROTECTED]> wrote: > Hello, > > In my real world model i would have a users that each can have one of > several available themes. > > So i would think this translates into a user table and a theme table. > In the user table there would be a field theme_id, right? > > How does this gets translated into a cake-hasOne association? Is > hasOne the right association to use? > > the hasOne association seems different in the examples, there the > owned model has a reference to the owner (through the foreignKey). In > my case it is vice versa. This led me to consider belongsTo as the > association, but this as well doesn't fit, because a theme can be used > by many users. > > So in my case, where the theme does not reference the user, but the > user references a theme, what association should i use? > > Thanks, > > pieter --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
question about hasOne association in 1.1
Hello, In my real world model i would have a users that each can have one of several available themes. So i would think this translates into a user table and a theme table. In the user table there would be a field theme_id, right? How does this gets translated into a cake-hasOne association? Is hasOne the right association to use? the hasOne association seems different in the examples, there the owned model has a reference to the owner (through the foreignKey). In my case it is vice versa. This led me to consider belongsTo as the association, but this as well doesn't fit, because a theme can be used by many users. So in my case, where the theme does not reference the user, but the user references a theme, what association should i use? Thanks, pieter --~--~-~--~~~---~--~~ 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: hasOne association
In your Player model: class Player extends AppModel { var $name = 'Player'; var $primaryKey = 'player_id';// <-- Without this, Cake assumes that the primary key of your model is named 'id'. var $hasOne = array('Playerstat' => array( 'className' =>'Playerstat', 'foreignKey' =>'player_id', 'dependent' => true )); } On May 22, 1:30 pm, cooked <[EMAIL PROTECTED]> wrote: > I am stumped with a problem when using model associations. For the > some reason the findAll generates an incorrect join query. Will great > appreciate any help. Both my models and controllers along with the > MySql output > is shown below. > > class Playerstat extends AppModel > { > var $name = 'Playerstat'; > var $belongsTo = array('Player' => array( > 'className' => 'Player', > 'foreignKey' => > 'player_id')); > > } > > class Player extends AppModel > { > var $name = 'Player'; > var $hasOne = array('Playerstat' => array( > 'className' => > 'Playerstat', > 'foreignKey' => > 'player_id', > 'dependent' => true)); > > } > > Each Player record has a corresponding Playerstat record. player_id is > the primary key in > table players and player_id is the foreign key in playerstat. > > I have the following code in one of my controller function > > $status = PLAYER_ACTIVE; > $results = $this->Player->findAll("Player.active = $status AND > Player.level = 'A'", > array("Player.fname", > "Player.lname", > "Playerstat.wins", "Playerstat.loss", > "Playerstat.points", > "Playerstat.last_played"), > 'Playerstat.points DESC'); > > I get the following result from MySql > > Query: SELECT `Player`.`fname`, `Player`.`lname`, `Playerstat`.`wins`, > `Playerstat`.`loss`, `Playerstat`.`points`, `Playerstat`.`last_played` > FROM `players` AS `Player` LEFT JOIN `playerstats` AS `Playerstat` ON > (`Playerstat`.`player_id` = `Player`.`id`) WHERE `Player`.`active` = 1 > AND `Player`.`level` = 'A' ORDER BY `Playerstat`.`points` DESC > > Warning (512): SQL Error: 1054: Unknown column 'Player.id' in 'on > clause' [CORE/cake/libs/model/datasources/dbo_source.php, line 440] > > The players table does not have an "id" field it is suppose to be > player_id. What I am doing wrong? How can I make "id" into > "player_id". > > 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 -~--~~~~--~~--~--~---
hasOne association
I am stumped with a problem when using model associations. For the some reason the findAll generates an incorrect join query. Will great appreciate any help. Both my models and controllers along with the MySql output is shown below. class Playerstat extends AppModel { var $name = 'Playerstat'; var $belongsTo = array('Player' => array( 'className' => 'Player', 'foreignKey' => 'player_id')); } class Player extends AppModel { var $name = 'Player'; var $hasOne = array('Playerstat' => array( 'className' => 'Playerstat', 'foreignKey' => 'player_id', 'dependent' => true)); } Each Player record has a corresponding Playerstat record. player_id is the primary key in table players and player_id is the foreign key in playerstat. I have the following code in one of my controller function $status = PLAYER_ACTIVE; $results = $this->Player->findAll("Player.active = $status AND Player.level = 'A'", array("Player.fname", "Player.lname", "Playerstat.wins", "Playerstat.loss", "Playerstat.points", "Playerstat.last_played"), 'Playerstat.points DESC'); I get the following result from MySql Query: SELECT `Player`.`fname`, `Player`.`lname`, `Playerstat`.`wins`, `Playerstat`.`loss`, `Playerstat`.`points`, `Playerstat`.`last_played` FROM `players` AS `Player` LEFT JOIN `playerstats` AS `Playerstat` ON (`Playerstat`.`player_id` = `Player`.`id`) WHERE `Player`.`active` = 1 AND `Player`.`level` = 'A' ORDER BY `Playerstat`.`points` DESC Warning (512): SQL Error: 1054: Unknown column 'Player.id' in 'on clause' [CORE/cake/libs/model/datasources/dbo_source.php, line 440] The players table does not have an "id" field it is suppose to be player_id. What I am doing wrong? How can I make "id" into "player_id". 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: Empty hasOne association
Hello Adam, thank you for your answer. > empty($location['ContactPerson']['id']) Yeah, I already checked this. :-) I think the reason for this "feature" is that only one SQL statement (LEFT JOIN) is necessary to fetch a record with its associated hasOne data. Regards, Christoph --~--~-~--~~~---~--~~ 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: Empty hasOne association
I've wondered about this too, however if cakephp core team thought it was a bug it would have been fixed by now. So obviously they do not consider it a bug. You can override this behaviour in your afterFind if you deem it necessary, however I would just do a check for empty($location['ContactPerson']['id']) On Apr 1, 4:54 pm, Preloader <[EMAIL PROTECTED]> wrote: > Any comments on this issue? :-) --~--~-~--~~~---~--~~ 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: Empty hasOne association
Any comments on this issue? :-) --~--~-~--~~~---~--~~ 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: hasOne association, Form and tagErrorMsg
i solved doing the next $this->User->data = $this->data; $UserValid = $this->User->validates(); this should validates the User fields and if there are some of them wrong, cake reconize them and invoque the tagErrorMsg $this->User->Profile->data = $this->data; $ProfileValid = $this->User->Profile->validates(); make the same with the Profile then you should if ($ProfileValid && $UserValid) then -> save both of them this worked for me Dr. Tarique Sani wrote: > > > Ran into this seemingly simple problem which I have not been able to solve > :( > > I have User model which hasOne Profile model > > The users/add view has fields for both User and Profile with > corresponding tagErrorMsg like > $html->tagErrorMsg("Users/username") and > $html->tagErrorMsg("Profile/fullname") etc > > In the users_controller - add action - I do > > $user_validates = $this->User->validates(); > > $profile_validates = $this->User->Profile->validates(); > > Subsequently I test if both are true and do the needful to save both > models. (setting user_id in profile after saving user and the works) > > - If the all data is valid saving works. > - If the User data is not valid I see error messages rendered via > tagErrorMsg > - BUT if Profile data is not valid no error messages are rendered. > > What would be the simplest way to solve this? > > In other words how to get tagErrorMsg to render validationErrors from > an associated hasOne model with minimal coding and what would be the > correct cakePHP way to do it. > > Thanks in advance > > Tarique > > -- > = > PHP for E-Biz: http://sanisoft.com > Cheesecake-Photoblog: http://cheesecake-photoblog.org > = > > > > -- View this message in context: http://www.nabble.com/hasOne-association%2C-Form-and-tagErrorMsg-tp8557744p15133510.html Sent from the CakePHP mailing list archive at Nabble.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: hasOne association question
Oh wait, I just figured it out. $unansweredQuestions = $this->Question->findAll(array('Answer.id' => null)); Had no idea I could just put null in there. Sweet, thanks. On Jan 27, 12:10 am, Corie <[EMAIL PROTECTED]> wrote: > Thanks for the reply Brian. > > Interesting thought on reversing the association, that would work > pretty well me thinks, but it doesn't follow the program logic. > > Shouldn't something like this work... > > $unansweredQuestions = $this->Question->findAll(array('Answer.id' => > '')); > > It just doesn't. > > On Jan 26, 10:17 pm, brian_gaff <[EMAIL PROTECTED]> wrote: > > > >>Is this proper behavior? It seems like it should not return an Answer > > > array at all. > > > Yes. You can do something like > > > if(isset($question['Answer']['id'])) > > { > > /* do something with answer */ > > } > > > You might consider reversing it and putting the foriegn key in the > > questions table, and having each Answer haveOne question and each > > Question belongTo an answer. If you do that you can do: > > > $questionsWithNoAns = $this->Question- > > > >findAll(array('Question.answer_id' => 0)); > > > On Jan 25, 12:18 pm, Corie <[EMAIL PROTECTED]> wrote: > > > > Using Cake 1.2, when I perform a findAll() on a model with a hasOne > > > association it's returning an array for the associated table even if > > > there is no record. > > > > Here's an example. > > > > // question.php > > > class Question extends AppModel > > > { > > > var $name = 'Question'; > > > var $hasOne = 'Answer'; > > > > } > > > > // answer.php > > > class Answer extends AppModel > > > { > > > var $name = 'Answer'; > > > var $belongsTo = 'Question'; > > > > } > > > > // questions_controller.php > > > class QuestionsController extends AppController > > > { > > > function index() > > > { > > > $questions = $this->Question->findAll(); > > > pr($questions); > > > } > > > > } > > > > // outputs > > > > Array > > > ( > > > [0] => Array > > > ( > > > [Question] => Array > > > ( > > > [id] => 4 > > > [question] => why? > > > [created] => 2008-01-25 00:23:44 > > > [ip] => 192.168.0.101 > > > ) > > > > [Answer] => Array > > > ( > > > [id] => > > > [question_id] => > > > [answer] => > > > [created] => > > > [name] => > > > ) > > > ) > > > ) > > > > Is this proper behavior? It seems like it should not return an Answer > > > array at all. > > > > Anyways, another question is, how would I go about finding only > > > questions which do not have answers? --~--~-~--~~~---~--~~ 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: hasOne association question
Thanks for the reply Brian. Interesting thought on reversing the association, that would work pretty well me thinks, but it doesn't follow the program logic. Shouldn't something like this work... $unansweredQuestions = $this->Question->findAll(array('Answer.id' => '')); It just doesn't. On Jan 26, 10:17 pm, brian_gaff <[EMAIL PROTECTED]> wrote: > >>Is this proper behavior? It seems like it should not return an Answer > > array at all. > > Yes. You can do something like > > if(isset($question['Answer']['id'])) > { > /* do something with answer */ > } > > You might consider reversing it and putting the foriegn key in the > questions table, and having each Answer haveOne question and each > Question belongTo an answer. If you do that you can do: > > $questionsWithNoAns = $this->Question- > > >findAll(array('Question.answer_id' => 0)); > > On Jan 25, 12:18 pm, Corie <[EMAIL PROTECTED]> wrote: > > > Using Cake 1.2, when I perform a findAll() on a model with a hasOne > > association it's returning an array for the associated table even if > > there is no record. > > > Here's an example. > > > // question.php > > class Question extends AppModel > > { > > var $name = 'Question'; > > var $hasOne = 'Answer'; > > > } > > > // answer.php > > class Answer extends AppModel > > { > > var $name = 'Answer'; > > var $belongsTo = 'Question'; > > > } > > > // questions_controller.php > > class QuestionsController extends AppController > > { > > function index() > > { > > $questions = $this->Question->findAll(); > > pr($questions); > > } > > > } > > > // outputs > > > Array > > ( > > [0] => Array > > ( > > [Question] => Array > > ( > > [id] => 4 > > [question] => why? > > [created] => 2008-01-25 00:23:44 > > [ip] => 192.168.0.101 > > ) > > > [Answer] => Array > > ( > > [id] => > > [question_id] => > > [answer] => > > [created] => > > [name] => > > ) > > ) > > ) > > > Is this proper behavior? It seems like it should not return an Answer > > array at all. > > > Anyways, another question is, how would I go about finding only > > questions which do not have answers? --~--~-~--~~~---~--~~ 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: hasOne association question
>>Is this proper behavior? It seems like it should not return an Answer array at all. Yes. You can do something like if(isset($question['Answer']['id'])) { /* do something with answer */ } You might consider reversing it and putting the foriegn key in the questions table, and having each Answer haveOne question and each Question belongTo an answer. If you do that you can do: $questionsWithNoAns = $this->Question- >findAll(array('Question.answer_id' => 0)); On Jan 25, 12:18 pm, Corie <[EMAIL PROTECTED]> wrote: > Using Cake 1.2, when I perform a findAll() on a model with a hasOne > association it's returning an array for the associated table even if > there is no record. > > Here's an example. > > // question.php > class Question extends AppModel > { > var $name = 'Question'; > var $hasOne = 'Answer'; > > } > > // answer.php > class Answer extends AppModel > { > var $name = 'Answer'; > var $belongsTo = 'Question'; > > } > > // questions_controller.php > class QuestionsController extends AppController > { > function index() > { > $questions = $this->Question->findAll(); > pr($questions); > } > > } > > // outputs > > Array > ( > [0] => Array > ( > [Question] => Array > ( > [id] => 4 > [question] => why? > [created] => 2008-01-25 00:23:44 > [ip] => 192.168.0.101 > ) > > [Answer] => Array > ( > [id] => > [question_id] => > [answer] => > [created] => > [name] => > ) > ) > ) > > Is this proper behavior? It seems like it should not return an Answer > array at all. > > Anyways, another question is, how would I go about finding only > questions which do not have answers? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
hasOne association question
Using Cake 1.2, when I perform a findAll() on a model with a hasOne association it's returning an array for the associated table even if there is no record. Here's an example. // question.php class Question extends AppModel { var $name = 'Question'; var $hasOne = 'Answer'; } // answer.php class Answer extends AppModel { var $name = 'Answer'; var $belongsTo = 'Question'; } // questions_controller.php class QuestionsController extends AppController { function index() { $questions = $this->Question->findAll(); pr($questions); } } // outputs Array ( [0] => Array ( [Question] => Array ( [id] => 4 [question] => why? [created] => 2008-01-25 00:23:44 [ip] => 192.168.0.101 ) [Answer] => Array ( [id] => [question_id] => [answer] => [created] => [name] => ) ) ) Is this proper behavior? It seems like it should not return an Answer array at all. Anyways, another question is, how would I go about finding only questions which do not have answers? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
hasOne Association should force only one register to be related?
Hello, i'm new both to php and cake, so please excuse me if this is another obvious noob question. I was trying to understand how associations work by building up the example in the manual section of cakephp.org, i was able to build it up using bake with no much effort. The thing is, i have a users table and a profiles table, they look like this: CREATE TABLE `profiles` ( `id` int(11) NOT NULL auto_increment, `name` varchar(100) collate utf8_unicode_ci NOT NULL, `header_color` varchar(100) collate utf8_unicode_ci NOT NULL, `user_id` int(11) NOT NULL, PRIMARY KEY (`id`), ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; CREATE TABLE `users` ( `id` int(11) NOT NULL auto_increment, `first_name` varchar(100) collate utf8_unicode_ci NOT NULL, `last_name` varchar(100) collate utf8_unicode_ci NOT NULL, `username` varchar(100) collate utf8_unicode_ci NOT NULL, `password` varchar(100) collate utf8_unicode_ci default NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; using bake i was able to create the models and to define the following associations User: var $hasOne = array('Profile' =>array('className' => 'Profile', 'foreignKey' => 'user_id', 'conditions' => '', 'fields' => '', 'order' => '', 'dependent' => ''),); Profile: var $belongsTo = array('User' =>array('className' => 'User', 'foreignKey' => 'user_id', 'conditions' => '', 'fields' => '', 'order' => '', 'counterCache' => ''),); Which seems good to me, but testing the application i was able to create a second profile for one user. I was guessing if the hasOne association should check that and return an error, or I am missing something? On the other hand, i builded the tables based on my own understanding of the example, maybe they are wrong, and so the whole example. I was thinking of adding an UNIQUE clause on the user_id so forcing only one profile per user but doing that causes the application to show an ugly error database message, which is correct and obviously i can take care of it, but not seems to follow the elegant and simple rules of the rest of the application. What also worries me is that in a hasOne association i would expect the users table to have a foreign key to the profiles table, not the contrary like in the example. I see I wrote a quite long message, I believe that giving the max info possible tends to help answering better responses and keeping threads short, but if its against forum rules, please let me know. Thanks in advance Chus --~--~-~--~~~---~--~~ 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: hasOne association, Form and tagErrorMsg
On 1/24/07, kitten <[EMAIL PROTECTED]> wrote: > > I stumbled over the same problem a few hours ago... > > var $uses = array('User', 'Profile'); I know and it does get the job done but not an optimal solution IMO Tarique -- = PHP for E-Biz: http://sanisoft.com Cheesecake-Photoblog: http://cheesecake-photoblog.org = --~--~-~--~~~---~--~~ 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: hasOne association, Form and tagErrorMsg
I stumbled over the same problem a few hours ago... var $uses = array('User', 'Profile'); in the controller solved it. Hope this helps :) Heiner > > On 1/24/07, AD7six <[EMAIL PROTECTED]> wrote: >> Did you try >> $user_validates = $this->User->validates($this->data); >> $profile_validates = $this->User->Profile->validates($this->data); > > Oh! I am doing corresponding calls to set before, however even with > the above it does not work - by now I know why it does not work - the > cakePHP code as I read it - is not designed to handle associations for > tagErrorMsg > > Thanks - more insights would be appreciated > > Regards > Tarique --~--~-~--~~~---~--~~ 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: hasOne association, Form and tagErrorMsg
On 1/24/07, AD7six <[EMAIL PROTECTED]> wrote: > Did you try > $user_validates = $this->User->validates($this->data); > $profile_validates = $this->User->Profile->validates($this->data); Oh! I am doing corresponding calls to set before, however even with the above it does not work - by now I know why it does not work - the cakePHP code as I read it - is not designed to handle associations for tagErrorMsg Thanks - more insights would be appreciated Regards Tarique -- = PHP for E-Biz: http://sanisoft.com Cheesecake-Photoblog: http://cheesecake-photoblog.org = --~--~-~--~~~---~--~~ 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: hasOne association, Form and tagErrorMsg
On Jan 24, 11:08 am, "Dr. Tarique Sani" <[EMAIL PROTECTED]> wrote: > Ran into this seemingly simple problem which I have not been able to solve :( > > I have User model which hasOne Profile model > > The users/add view has fields for both User and Profile with > corresponding tagErrorMsg like > $html->tagErrorMsg("Users/username") and > $html->tagErrorMsg("Profile/fullname") etc > > In the users_controller - add action - I do > > $user_validates = $this->User->validates(); > > $profile_validates = $this->User->Profile->validates(); > > Subsequently I test if both are true and do the needful to save both > models. (setting user_id in profile after saving user and the works) > > - If the all data is valid saving works. > - If the User data is not valid I see error messages rendered via tagErrorMsg > - BUT if Profile data is not valid no error messages are rendered. > > What would be the simplest way to solve this? > > In other words how to get tagErrorMsg to render validationErrors from > an associated hasOne model with minimal coding and what would be the > correct cakePHP way to do it. > > Thanks in advance > > Tarique > > -- > = > PHP for E-Biz:http://sanisoft.com > Cheesecake-Photoblog:http://cheesecake-photoblog.org > = Did you try $user_validates = $this->User->validates($this->data); $profile_validates = $this->User->Profile->validates($this->data); HTH, AD7six Please note: The manual/bakery is a good place to start any quest for info. The cake search (at the time of writing) erroneously reports less/no results for the google group. The wiki may contain incorrect info - read at your own risk (it's mainly user submitted) :) You may get your answer quicker by asking on the IRC Channel (you can access it with just a browser here:http://irc.cakephp.org). --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
hasOne association, Form and tagErrorMsg
Ran into this seemingly simple problem which I have not been able to solve :( I have User model which hasOne Profile model The users/add view has fields for both User and Profile with corresponding tagErrorMsg like $html->tagErrorMsg("Users/username") and $html->tagErrorMsg("Profile/fullname") etc In the users_controller - add action - I do $user_validates = $this->User->validates(); $profile_validates = $this->User->Profile->validates(); Subsequently I test if both are true and do the needful to save both models. (setting user_id in profile after saving user and the works) - If the all data is valid saving works. - If the User data is not valid I see error messages rendered via tagErrorMsg - BUT if Profile data is not valid no error messages are rendered. What would be the simplest way to solve this? In other words how to get tagErrorMsg to render validationErrors from an associated hasOne model with minimal coding and what would be the correct cakePHP way to do it. Thanks in advance Tarique -- = PHP for E-Biz: http://sanisoft.com Cheesecake-Photoblog: http://cheesecake-photoblog.org = --~--~-~--~~~---~--~~ 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: when hasone association is used, find() returns nothing
> > class User extends AppModel { > var $name = 'User'; > } > > class Review extends AppModel { > var $name = 'Review'; > > var $hasOne = array('User' => > array('className' => 'User', > 'conditions' => '', > 'order' => '', > 'dependent' => false, > 'foreignKey' => 'user_id' > ) > ); I don't know if this is your problem, but it looks like you should be using 'belongsTo' instead of 'hasOne'. If a review has one user, then the user should have a field 'review_id'. What you want to say is that the review belongs to a user (ie. review has a 'user_id') field. To remember this, think in terms of 'hasMany' -- if a review has many users, then the review would need many 'user_id' fields -- which doesn't work, therefore the field has to be in User (review_id). 'hasOne' is just a special case of 'hasMany'. Hope this makes sense, Anselm --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
when hasone association is used, find() returns nothing
Hi there, I have two models, User and Review, each Review has one user associated with it, so I use the "hasone" in Review's model, however once I use hasone, any find() or findAll() from Review's controller returns empty array... it works if hasone is removed, anyone knows why? array('className' => 'User', 'conditions' => '', 'order' => '', 'dependent' => false, 'foreignKey' => 'user_id' ) ); } ?> --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---