Thursday, December 30, 2010

Re: URGENT - Help needed - Model Association

How are you including $user_id? There are more than one approache you can take:

echo $this->Form->hidden('Post.user_id', array('value' =>
$this->Session->read('Auth.User.id')));

Or you can add it to the submitted data inside the controller:

if (!empty($this->data))
{
$this->data['Post']['user_id'] = $this->Auth->user('id');

On Thu, Dec 30, 2010 at 12:03 AM, Karthikeyan P <pkaarthikeyan@gmail.com> wrote:
> John
>
>   I think the class name conventions are correct as the code is a generated
> one ..I didn't write the code.It was generated by "cake bake" command .
>
> " Model 'Comment' has a 'comments' table, not a 'Comments'
> table. "
>
> I have not defined anywhere as Comments Table..I have done as comments only
>
> I guess the problem is in the relationship type during the model association
> ? Not sure though
>
> Thanks
> Karthikeyan P
>
> On Thu, Dec 30, 2010 at 4:08 AM, john lyles <confidential99@gmail.com>
> wrote:
>>
>> If the model names are Post and User then the table names should be
>> 'posts' and 'users' lowercased. The field name is 'user_id' not
>> 'UserId'. Model 'Comment' has a 'comments' table, not a 'Comments'
>> table. You have to respect CakePHP's File and Classname conventions,
>> see section 2.4.1 in the manual.
>>
>> On Dec 29, 11:19 am, pinastro <pkaarthike...@gmail.com> wrote:
>> > I have created a Blog Application using a base table as 'Posts'. Later
>> > Model-Associated with another table 'Users' with 'belongsTo'
>> > relationship like below in the MODEL
>> >
>> > var $belongsTo = array(
>> > 'User' => array(
>> > 'className' => 'User',
>> > 'foreignKey' => 'user_id',
>> > 'conditions' => '',
>> > 'fields' => '',
>> > 'order' => ''
>> > )
>> > );
>> >
>> > But still I am not able to store the UserId in the Posts Table ???
>> > What's the Problem
>> >
>> > Plus what does the following lines of code mean :: I saw the
>> > comments_controller.php which got generated using the BAKE command
>> > when MODEL ASSOCIATED the 'Posts' table with the 'Comments' Table :
>> >
>> > $posts = $this->Comment->Post->find('list');
>> > $this->set(compact('posts'));
>> >
>> > If not above ; is there anyway I can store the UserId in the Posts
>> > Table using Model Associated cakePHP application ?
>>
>> 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+unsubscribe@googlegroups.com For more options, visit this group
>> at http://groups.google.com/group/cake-php?hl=en
>
> Check out the new CakePHP Questions site http://cakeqs.org and help others
> with their CakePHP related questions.
>
> You received this message because you are subscribed to the Google Groups
> "CakePHP" group.
> To post to this group, send email to cake-php@googlegroups.com
> To unsubscribe from this group, send email to
> cake-php+unsubscribe@googlegroups.com For more options, visit this group at
> http://groups.google.com/group/cake-php?hl=en
>

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: