top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to apply association in Cakephp?

0 votes
320 views
How to apply association in Cakephp?
posted Aug 7, 2014 by Karamjeet Singh

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Association means linking the different models together in CakePHP.
Relationship Types: There are four type of association types.

Relationship Association Type
one to one hasOne
one to many hasMany
many to one belongsTo
many to many hasAndBelongsToMany
Example: Suppose you are having two different tables named as 'products' and 'categories'. A product belongs to a particular category and a category can have many products. So your association in the Product model will be like as following:

class Product extends AppModel {
public $belongsTo= 'Category';
}
and for category model,your association will be as following:

class Categories extends AppModel{
public $hasMany =array('Product'=>array('className'=>'Product'));
}

answer Aug 10, 2014 by Amritpal Singh
Similar Questions
+2 votes

Missing Controller
Error: Cakephp controller could not be found
Error: create the class cakephpcontroller below in file:app\controller\cakephpcontroller.php

<?php
class cakephpcontroller extends AppController {
}

Stack Trace
App\webroot\index.php line 108
dispatcher->dispatch(cakerequest,cakeresponse)
root\index.php line 41 -> require(string

These are errors, please help us?

...