>From something,I'm currently working on (I've changed my Models to
yours, but only names)
//paginator variable:
$this->paginate = array('Asset' => array(
'limit' => 10,
'order' => array('Asset.promoted DESC', 'Asset.name ASC'),
'conditions' => array(
'Asset.accepted' => 1,
),
//@todo 'fields' => array(),
'joins' => array(
array(
'table' => 'assets_containers',
'alias' => 'AssetsContainer',
'type' => 'INNER',
'conditions' => array(
'AssetsContainer.asset_id = Asset.id'
)
),
array(
'table' => 'containers',
'alias' => 'Container',
'type' => 'INNER',
'conditions' => array(
'Container.id = AssetsContainer.container_id',
'Container.link_name' => $parameters // just
Container_id => $id form function params
)
),
),
));
$assets = $this->paginate('Asset');
$this->set('assets', $assets);
This is in index action of assets_controller, but it will (should?)
work in Container, with proper settings.
I found this way very easy to paginate HABTM models (after fighting
with nasty bindModel and found the 'joins' savior).
But for the other question, i have no clue now... how to work with
three models on one _id field. (easiest would be creating three
fields, in assets table: photo_id, profile_id and blog_id - but i
guess it's not nicest way... just an idea to make it work
automatically loads photo, profile or blog data - the only thing is
that you have ensure that only one id is set - photo, blog or
profile).
On Dec 3, 12:07 pm, Martin Westin <[email protected]> wrote:
> About the pagination:http://book.cakephp.org/view/83/hasAndBelongsToMany-HABTM
> Look at the bottom. The last examples abut binding can be used to let
> paginator deal with your habtm.
>
> When it comes to finding related data find is better than read. But
> probably find('first') in this case since it does more or less the
> same as read. Use Containable to specify what and how deep you want
> your data returned. That should do it...
>
> On Dec 3, 4:02 am, "Alan Asher" <[email protected]> wrote:
>
> > I've been scouring the web for a while trying to figure this out. My brain
> > is fried, so I need some help.
>
> > I have a model called Containers, a model called Assets and HABTM table
> > called AssetsContainer.
>
> > So a container can have many assets.
>
> > The first question I have is when I'm doing this operation
>
> > $this->Container->read(null,$id);
>
> > How do I paginate the assets. right now I am only testing so there's only 2
> > assets linked to the container. Am I assuming right that there would be an
> > endless number of assets? If not, still, how do I paginate this data?
>
> > Next question is, each asset can be one of three different tables, Photos,
> > Profiles, Blogs. Each of these models has a hasOne relationship of asset_id
> > in each model. How do I get the read() function to retrieve this data
> > automatically? My first instinct is to put a nominal field for each
> > potential table of photo_id, profile_id and blog_id and update the model for
> > Asset with the hasOne of each.. This way it will grab the data right?
>
> > Also, is this an instance where instead of read, I use find('all') instead?
>
> > Many thanks,
>
> > Alan
>
> > Example of my Container->read below
>
> > Array
> > (
> > [Container] => Array
> > (
> > [id] => 1
> > [user_id] => 1
> > [title] => Default
> > [total_items] =>
> > [mime_type] => image
> > [photo_id] => 1
> > [created] => 2009-12-02 11:53:21
> > [modified] => 2009-12-02 11:53:21
> > [is_fan_club] => 0
> > [fan_club_requirements] =>
> > [nsfw] => 0
> > [ordering] =>
> > [active] =>
> > [deleted] =>
> > )
>
> > [User] => Array
> > (
> > [id] => 1
> > [user_type_id] => 2
> > [user_group_id] => 3
> > [username] => user
> > [email] =>
> > [name] =>
> > [gender_id] => 1
> > [password] =>
> > [salt] =>
> > [birthday] => 1991-11-23
> > [created] => 2009-11-23 21:41:24
> > [modified] => 2009-11-24 15:24:59
> > )
>
> > [Photo] => Array
> > (
> > [id] => 1
> > [user_id] => 1
> > [asset_id] => 15
> > [created] => 1259625133
> > [modified] => 1259625133
> > [title] =>
> > [deleted] =>
> > [file_name] => c0a80aa6-5aab-f111.jpg
> > [rel_path] => users/1/2009/11
> > [caption] =>
> > [server_id] => 1
> > [is_featured] =>
> > )
>
> > [Asset] => Array
> > (
> > [0] => Array
> > (
> > [id] => 1
> > [asset_type_id] =>
> > [user_id] =>
> > [created] => 2009-11-30 16:12:05
> > [modified] => 2009-11-30 16:12:05
> > [ordering] => 0
> > [allow_comments] => 1
> > [allow_rates] => 1
> > [nsfw] => 0
> > [total_views] => 0
> > [total_rates] => 0
> > [total_rating] => 0
> > [total_comments] => 0
> > [AssetsContainer] => Array
> > (
> > [id] => 1
> > [asset_id] => 1
> > [container_id] => 1
> > [ordering] => 1
> > [created] =>
> > [modified] =>
> > )
>
> > )
>
> > [1] => Array
> > (
> > [id] => 2
> > [asset_type_id] =>
> > [user_id] =>
> > [created] => 2009-11-30 16:13:47
> > [modified] => 2009-11-30 16:13:47
> > [ordering] => 0
> > [allow_comments] => 1
> > [allow_rates] => 1
> > [nsfw] => 0
> > [total_views] => 0
> > [total_rates] => 0
> > [total_rating] => 0
> > [total_comments] => 0
> > [AssetsContainer] => Array
> > (
> > [id] => 2
> > [asset_id] => 2
> > [container_id] => 1
> > [ordering] => 2
> > [created] =>
> > [modified] =>
> > )
>
> > )
>
> > )
>
> > )
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 [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en