[LRUG] REST and Associations

Jonathan Leighton turnip at turnipspatch.com
Wed Feb 21 15:16:45 PST 2007


So I've been playing with REST lately and it all seems pretty spiffy but
I am a little confused on the issue of associations.

Issue #1
--------

We have a large database with a lot of tables and a lot of
relationships. The client wants to be able to create a new resource, and
said resource has lots of required associations. It would not make sense
to create these associations separately to the original resource so that
is happening all in one form on one page. Is this okay? That doesn't
make me a bad person in DHH's eyes does it?

Issue #2
--------

Similar to #1. Said resource has a has_and_belongs_to_many association.
In the non-RESTful version, these were selected from select boxes. When
creating a new resource, you'd be presented with one select box. If you
wanted another you could click "add another". This would post the page
back to the "new" action, which would recognise which submit button had
been pressed and redraw the form with one more select box (and therefore
association).

This is all fine and dandy but in the happy land of REST the form gets
posted to the "create" action. I guess the fundamental problem is
actually that in order to do the same thing I'd have to allow the create
action to re-show the form with the additional select box(es). That
would surely be evil and if DHH didn't think I'm a bad person for #1 he
surely would now.

At the moment I am handling it by having an #add_foo action and calling
that via ajax, which inserts the new select box. This is blatently evil
in a progressive enhancement sorta way but seems less evil in a RESTful
way.

Either way I am evil though. Help!

Thanks :)

-- 
Jonathan Leighton, Web Developer
Portfolio: http://jonathanleighton.com/
Personal: http://turnipspatch.com/




More information about the Chat mailing list