Forum: Ruby on Rails Bad idea to add/remove associations in after_find

Posted by Paul Olivers (foxert)
on 2012-12-25 00:28
I have 2 distinct types of users (artists and curators) in my system and
they currently share all associations (eg has_one :portfolio).
However, a curator shouldn't have a portfolio so I would like to only
add that association when required. Obviously I could just return nil
for that method, but it doesn't feel right having that there in the
first place.

What's the best way to get around this? I've looked at using eval in
after_find to call the has_one, but couldn't get it working.

Any thoughts?

thanks!
Posted by tamouse mailing lists (Guest)
on 2012-12-25 02:25
(Received via mailing list)
On Mon, Dec 24, 2012 at 5:28 PM, Paul Olivers <lists@ruby-forum.com> 
wrote:
> Any thoughts?
Can an artist also be a curator?
Posted by Frederick Cheung (Guest)
on 2012-12-25 13:15
(Received via mailing list)
On Dec 24, 11:28pm, Paul Olivers <li...@ruby-forum.com> wrote:
> I have 2 distinct types of users (artists and curators) in my system and
> they currently share all associations (eg has_one :portfolio).
> However, a curator shouldn't have a portfolio so I would like to only
> add that association when required. Obviously I could just return nil
> for that method, but it doesn't feel right having that there in the
> first place.
>
> What's the best way to get around this? I've looked at using eval in
> after_find to call the has_one, but couldn't get it working.

Have you considered STI ?

Fred
Posted by Dheeraj Kumar (Guest)
on 2012-12-25 13:18
(Received via mailing list)
+1 for STI, if an artist cannot be a curator.
Roles with CanCan, if an artist can be a curator.


--
Dheeraj Kumar
Posted by Rajarshi (Guest)
on 2012-12-26 11:12
(Received via mailing list)
better use cancan also you can create type filed make
polymorphic ossification  and create different users of different roles
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.