eager-loading


How to enable eager loading on a association in phpactiverecord?


I have an phpactiverecord Model "Category". This Model has a self-referential has_many association, and two has_one associations to another Model.
class Category extends Model {
static $table_name = 'categories';
static $has_many = array(
array(
'child_categories',
'class_name' => 'Category',
'primary_key' => 'categories_id',
'foreign_key' => 'parent_id'
)
);
static $has_one = array(
array(
'german_description',
'class_name' => 'CategoryDescription',
'primary_key' => 'categories_id',
'foreign_key' => 'categories_id',
'conditions' => 'language_id = 2'
),
array(
'english_description',
'class_name' => 'CategoryDescription',
'primary_key' => 'categories_id',
'foreign_key' => 'categories_id',
'conditions' => 'language_id = 1'
)
);
}
I can eager-load the has_one associations when I find Category, this works without any problem:
$category = ActiveRecord\Category::find(
$category_id,
array(
'include' => array( 'german_description', 'english_description' )
)
);
My problem is: When I iterate through all of a category's child-categories, and access the child-categories' has-one associations...
foreach( $category->child_categories as $child_category ){
echo $child_category->german_description->categories_name;
}
..then a new query is run every time I do so, becauce the child-category's has-one associations are not eager loaded.
My question is: Is it possible to configure access a categories child-categories in a way that eager-loads the child-categories' has-one associations?

Related Links

How to enable eager loading on a association in phpactiverecord?
Rails eager loading with conditions
Rails eager loading and conditions
Eager loading for globalize2 translations

Categories

HOME
google-chrome
visual-studio
android-studio
generics
qc
fedora
minecraft
roku
lapack
parsley.js
global-variables
synthesis
nest-api
rpmbuild
codefluent
significance
deepfreeze
adminlte
sqlplus
fido-u2f
kamailio
gollum-wiki
connection-refused
substring
restier
unordered-multimap
background-color
onchange
credit-card
reporting
fotorama
seafile-server
jfxtras
nppexec
redgate
testlink
recovery
windows-store
1wire
qvtkwidget
android-5.0-lollipop
redisson
maven-jaxb2-plugin
gtk#
asp.net-web-api-routing
gmaps.js
boost-compute
portal
jpda
carmen
system.net.mail
seccomp
oci
unsigned
apache-pig-grunt
i2b2
django-validation
boost-proto
in-app-billing
self
largenumber
ruby-on-rails-4.1
wso2ml
blockquote
unhandled
karma-coverage
shell-extensions
datagridcomboboxcolumn
xml-signature
window-resize
nesper
zend-search-lucene
unrealscript
mp4parser
quickgraph
indesign-server
insertion
ui-design
proc-open
significant-digits
icenium
xalan
towers-of-hanoi
idispatch
kaazing
monocross
qtextbrowser
motodev-studio
uipasteboard
suphp
active-record-query
hungarian-notation
bass
facebook-fbml
mysqli-multi-query
datagridcolumn
regioninfo
rootkit

Resources

Encrypt Message