The include option in your criteria should name the association for what you want included. In your results, you should see an array of Advertisement Objects. Within each of those Advertisement Objects, you'd have a nested array of elements named the same name as your association.
Easiest way is to print_r or var_dump your results.
$advertisements = Advertisements::find($criteria);
print_r($advertisements);
I have three tables as show above
and
In Advertisment model i used
static $belongs_to = array(array('categarogy'))
In Categarogy model i used
static $belongs_to = array(array('section'))
static $has_many = array(array('advertisment'))
In Section model model i used
static $has_many = array(array('categarogy '))
I what i am trying to do is
Advertisment::find('all',array('include'=>array('category'))) /****its work****/
But how we get the section model in above find
And
Section::find('all',array('include'=>array('category'))) /****its not work****/
how how we got the result for the above
Make sure you aren't actually using "categarogy" because that's quite a typo.
Also, it's usually just safer to always specify the class and foreign key in the array.
$has_many = array(
array('categarogy ', 'class_name'=>'Category', 'foreign_key'=>'section_id') // MAKE SURE YOU FIX "Categarogy"
)
Yes Thats the typo mistake Its the categroy.
I used your answer but its still giving error
'Relationship named corporation has not been declared for class
When i am trying to used following
Section::find('all',array('include'=>array('category'))) /****its not work****/
if you get rid of the include, does it still work?
Ideally after you do $section = Section::all();
You can then do foreach($section->categories as $category) .. Also rename it to categories since you have multiple categories for each section.
Oh Finally figure it out
Section::find('all',array('include'=>array('categories')))
Its take there table name while you call it from the has_many relationship model class object
Thanks for helping
Yay !
If you fill out all of the parameters, it takes whatever the first part of the $has_many array is for the relation.
IE $has_many = array('best_categories','class_name'=>'Category','foreign_key'=>'cat','conditions'=>'best=1');
$has_many = array('worst_categories','class_name'=>'Category','foreign_key'=>'cat','conditions'=>'best=0');
$section->best_categories , $section->worst_categories
Oh Thats very nice . :-)
Thanks buddy its very nice.
(1-8/8)
Subject: Cascade the include
Hi all,
I am new to spark and I need your help
I have following three tables
Advertisements-> id title categarogy_id
Categories-> id name section_id
Sections->id name
Now how can i get the details of the section with the advertisement object by using include