Last active
August 29, 2015 14:01
-
-
Save shahariaazam/b4d7214ab189b76d7cb9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // model/Article.php | |
| App::uses('AppModel', 'Model'); | |
| class Article extends AppModel | |
| { | |
| public $hasAndBelongsToMany = array( | |
| 'Category' => | |
| array( | |
| 'className' => 'Category', | |
| 'joinTable' => 'articles_categories', | |
| 'foreignKey' => 'article_id', | |
| 'associationForeignKey' => 'category_id', | |
| 'unique' => true | |
| ) | |
| ); | |
| } | |
| // controllers/ArticlesController.php | |
| class ArticlesController extends AppController | |
| { | |
| public function test() | |
| { | |
| $articlesFromCatOne = $this->Article->find('all', array('conditions' => array('Category.id' => 1))); | |
| var_dump($articlesFromCatOne); die(); | |
| } | |
| } | |
| // model/Category.php | |
| // class Category extends AppModel | |
| { | |
| public $hasAndBelongsToMany = array( | |
| 'Article' => | |
| array( | |
| 'className' => 'Article', | |
| 'joinTable' => 'articles_categories', | |
| 'foreignKey' => 'category_id', | |
| 'associationForeignKey' => 'article_id', | |
| 'unique' => true | |
| ) | |
| ); | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
But when I visit
../articles/testthen it shows the following errorBut I wanted to show all articles from a specific category. So what's the wrong I can't get it. It may be silly but my brain is being fucked up! LOL
The details debug output given for deep investigation:
# Stack Trace
array()
'SELECT
Article.id,Article.title,Article.slug,Article.description,Article.status,Article.read,Article.modified,Article.createdFROMdealerportal_kb.articlesASArticleWHERECategory.id= 1'array()
'SELECT
Article.id,Article.title,Article.slug,Article.description,Article.status,Article.read,Article.modified,Article.createdFROMdealerportal_kb.articlesASArticleWHERECategory.id= 1'array()
array()
'SELECT
Article.id,Article.title,Article.slug,Article.description,Article.status,Article.read,Article.modified,Article.createdFROMdealerportal_kb.articlesASArticleWHERECategory.id= 1'false
object(Article) {
hasAndBelongsToMany => array(
[maximum depth reached]
)
recursive => (int) -1
actsAs => array(
[maximum depth reached]
)
useDbConfig => 'default'
useTable => 'articles'
id => false
data => array([maximum depth reached])
schemaName => 'dealerportal_kb'
table => 'articles'
primaryKey => 'id'
validate => array([maximum depth reached])
validationErrors => array([maximum depth reached])
validationDomain => null
tablePrefix => ''
plugin => null
name => 'Article'
alias => 'Article'
tableToModel => array(
[maximum depth reached]
)
cacheQueries => false
belongsTo => array([maximum depth reached])
hasOne => array([maximum depth reached])
hasMany => array([maximum depth reached])
Behaviors => object(BehaviorCollection) {}
whitelist => array([maximum depth reached])
cacheSources => true
findQueryType => 'all'
order => null
virtualFields => array([maximum depth reached])
__backAssociation => array([maximum depth reached])
__backInnerAssociation => array([maximum depth reached])
__backOriginalAssociation => array([maximum depth reached])
__backContainableAssociation => array([maximum depth reached])
findMethods => array(
[maximum depth reached]
)
Category => object(Category) {}
[protected] _schema => array(
[maximum depth reached]
)
[protected] _associationKeys => array(
[maximum depth reached]
)
[protected] _associations => array(
[maximum depth reached]
)
[protected] _insertID => null
[protected] _sourceConfigured => true
[protected] _eventManager => object(CakeEventManager) {}
[protected] _validator => null
}
array(
'conditions' => array(
'Category.id' => (int) 1
),
'fields' => null,
'joins' => array(),
'limit' => null,
'offset' => null,
'order' => array(
(int) 0 => null
),
'page' => (int) 1,
'group' => null,
'callbacks' => true
)
'all'
array(
'conditions' => array(
'Category.id' => (int) 1
),
'fields' => null,
'joins' => array(),
'limit' => null,
'offset' => null,
'order' => array(
(int) 0 => null
),
'page' => (int) 1,
'group' => null,
'callbacks' => true
)
'all'
array(
'conditions' => array(
'Category.id' => (int) 1
)
)
[internal function] → ArticlesController->test()
object(ArticlesController) {
components => array(
[maximum depth reached]
)
uses => array(
[maximum depth reached]
)
name => 'Articles'
helpers => array([maximum depth reached])
request => object(CakeRequest) {}
response => object(CakeResponse) {}
viewPath => 'Articles'
layoutPath => null
viewVars => array([maximum depth reached])
view => 'test'
layout => 'default'
autoRender => true
autoLayout => true
Components => object(ComponentCollection) {}
viewClass => 'View'
View => null
ext => '.ctp'
plugin => null
cacheAction => false
passedArgs => array([maximum depth reached])
scaffold => false
methods => array(
[maximum depth reached]
)
modelClass => 'Article'
modelKey => 'article'
validationErrors => null
Session => object(SessionComponent) {}
Auth => object(AuthComponent) {}
Article => object(Article) {}
[protected] _responseClass => 'CakeResponse'
[protected] _mergeParent => 'AppController'
[protected] _eventManager => object(CakeEventManager) {}
}
array()
object(CakeRequest) {
params => array(
[maximum depth reached]
)
data => array([maximum depth reached])
query => array([maximum depth reached])
url => 'articles/test'
base => ''
webroot => '/'
here => '/articles/test'
[protected] _detectors => array(
[maximum depth reached]
)
[protected] _input => ''
}
object(ArticlesController) {
components => array(
[maximum depth reached]
)
uses => array(
[maximum depth reached]
)
name => 'Articles'
helpers => array([maximum depth reached])
request => object(CakeRequest) {}
response => object(CakeResponse) {}
viewPath => 'Articles'
layoutPath => null
viewVars => array([maximum depth reached])
view => 'test'
layout => 'default'
autoRender => true
autoLayout => true
Components => object(ComponentCollection) {}
viewClass => 'View'
View => null
ext => '.ctp'
plugin => null
cacheAction => false
passedArgs => array([maximum depth reached])
scaffold => false
methods => array(
[maximum depth reached]
)
modelClass => 'Article'
modelKey => 'article'
validationErrors => null
Session => object(SessionComponent) {}
Auth => object(AuthComponent) {}
Article => object(Article) {}
[protected] _responseClass => 'CakeResponse'
[protected] _mergeParent => 'AppController'
[protected] _eventManager => object(CakeEventManager) {}
}
object(CakeRequest) {
params => array(
[maximum depth reached]
)
data => array([maximum depth reached])
query => array([maximum depth reached])
url => 'articles/test'
base => ''
webroot => '/'
here => '/articles/test'
[protected] _detectors => array(
[maximum depth reached]
)
[protected] _input => ''
}
object(CakeResponse) {
[protected] _statusCodes => array(
[maximum depth reached]
)
[protected] _mimeTypes => array(
[maximum depth reached]
)
[protected] _protocol => 'HTTP/1.1'
[protected] _status => (int) 200
[protected] _contentType => 'text/html'
[protected] _headers => array([maximum depth reached])
[protected] _body => null
[protected] _file => null
[protected] _fileRange => null
[protected] _charset => 'UTF-8'
[protected] _cacheDirectives => array([maximum depth reached])
[protected] _cookies => array([maximum depth reached])
}
object(CakeRequest) {
params => array(
[maximum depth reached]
)
data => array([maximum depth reached])
query => array([maximum depth reached])
url => 'articles/test'
base => ''
webroot => '/'
here => '/articles/test'
[protected] _detectors => array(
[maximum depth reached]
)
[protected] _input => ''
}
object(CakeResponse) {
[protected] _statusCodes => array(
[maximum depth reached]
)
[protected] _mimeTypes => array(
[maximum depth reached]
)
[protected] _protocol => 'HTTP/1.1'
[protected] _status => (int) 200
[protected] _contentType => 'text/html'
[protected] _headers => array([maximum depth reached])
[protected] _body => null
[protected] _file => null
[protected] _fileRange => null
[protected] _charset => 'UTF-8'
[protected] _cacheDirectives => array([maximum depth reached])
[protected] _cookies => array([maximum depth reached])
}
(accounts) 1 query took 1 ms
Nr Query Error Affected Num. rows Took (ms)
1 SELECT
Session.id,Session.data,Session.expiresFROMdealerportal_accounts.cake_sessionsASSessionWHEREid= 'u080be1h6cbe31ao5j1mdve313' LIMIT 1 1 1 1(default) 0 query took ms
Nr Query Error Affected Num. rows Took (ms)
MySQL Schema