That seems reasonable to me. To keep things clear, you can assign an
alias to the models. So User could become Auditor in the context of
reading Accounts which are not theirs, and Account could become, eg.
Ledger. You could probably come up with better aliases.
Account.php:
public $hasAndBelongsToMany = array(
'Auditor' => array (
'className' => 'User',
'joinTable' => 'accounts_users',
'foreignKey' => 'user_id',
'associationForeignKey' => 'account_id'
)
);
User.php:
public $hasAndBelongsToMany = array(
'Ledger' => array (
'className' => 'Account',
'joinTable' => 'accounts_users',
'foreignKey' => 'account_id',
'associationForeignKey' => 'user_id'
)
);
So, for example, if you did a find on a given Account, all of the
Users which have read-only access to it would be under Auditor in the
data array. And, if you did the same for a given User, there would be
an array Ledger with all Accounts to which this User has access.
On Tue, Jun 26, 2012 at 1:44 PM, Janne Johansson <janjoh74@gmail.com> wrote:
> Hello!
>
> I am pretty much a complete newbie in regards to Cake, so I am looking for
> advice on how to best go abpuit the design of an app.
>
> Basically, I have a structure where i have:
>
> "Users" that hasMany "Accounts".
> "Accounts" hasMany "transactions".
>
> No magic there... But, I want a model where a User can assign read access to
> their "accounts" to another user. And I wonder how to best acheive that
> within the framework?
>
> I thought about a "HABTM" between users and acounts, but that seem a bit
> messy?
>
> --
> Our newest site for the community: CakePHP Video Tutorials
> http://tv.cakephp.org
> Check out the new CakePHP Questions site http://ask.cakephp.org and help
> others with their CakePHP related questions.
>
>
> To unsubscribe from this group, send email to
> cake-php+unsubscribe@googlegroups.com For more options, visit this group at
> http://groups.google.com/group/cake-php
--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Tuesday, June 26, 2012
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment