[jifty-devel] Propose a way to for a multi-valued field

Jesse Vincent jesse at bestpractical.com
Wed Apr 11 18:28:55 EDT 2007


Because I fear that I may not get to a proper reply today. (Still  
badly jetlagged from .jp)

Oh my god is this cool. :)

On Apr 11, 2007, at 1:59 PM, Kang-min Liu wrote:

> Hi all,
>
> When I'm crafting a simple "online order management" system I  
> realized that I need
> to input things easily while the relation between an "Order" class  
> and "OrderItem" class
> is an attributed many-to-many relation.
>
> The basic interface is in this picture:
>
>   http://flickr.com/photos/gugod/455575089/
>
> Please notice that in the column of "Products" which I add a flickr  
> note on it.
> There are 3 text fields  and their labels to the right.
> Values of labels are retrieved from "Product" model class.
>
> The schema of Order and OrderItem are:
>
> ---->8----
> # Order.pm
> use Opcafe::Record schema {
>     column
>         created_on => type is 'timestamp',
>         label is 'Time', filters are 'Jifty::DBI::Filter::DateTime';
>     column items =>
>         refers_to Opcafe::Model::OrderItemCollection by "order_id";
>     column males =>
>         type is "integer";
>     column females =>
>         type is "integer";
>     column takeout =>
>         type is "boolean";
> };
>
> # OrderItem.pm
> use Opcafe::Record schema {
>     column order_id =>
>         refers_to Opcafe::Model::Order, label is 'Order';
>     column product =>
>         refers_to Opcafe::Model::Product, label is 'Product';
>     column quantity =>
>         type is 'integer';
> };
> ----8<----
>
> As you can see, the "quantity" field here is what I called the  
> "attribute"
> on the relation. I consult to Handel framework, and this is also how
> it deal with the relation between an order and items in an order.
> So I just re-use their design here.
>
> I ended up with this solution:
>
>  1. Craft a Jifty/Web/Form/Field/MultiText.pm from Radio.pm.
>     Display many text fields instead of a set of radio buttons.
>
>  2. Define CreateOrder.pm that properly catch the values from  
> MultiText field,
>     and creates records in both Order model and OrderItem mode.
>
> I attached both .pm files to this mail.
>
> If this interface looks good to you guys I think it should be  
> committed into
> jifty core and J::A::Record::* should also be updated to be aware of
> multi-valued field, and do the right thing.
>
> (Yes, I know that I should check the return value of ->create in  
> CreateOrder.pm)
>
> Since this isn't just good for admin interface, it also helps users  
> (a lot)
> to create their own CRUD interface quickly. We could also come up  
> with other
> nice multi-valued field. e.g. MultiCheckbox, MultiSelect.
>
> Of course, the other way around is to let current Field/* classes
> be aware of that it's rendering a multi-valued field, and DWIM.
>
> <MultiText.pm>
> <CreateOrder.pm>
> _______________________________________________
> jifty-devel mailing list
> jifty-devel at lists.jifty.org
> http://lists.jifty.org/cgi-bin/mailman/listinfo/jifty-devel

-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 186 bytes
Desc: This is a digitally signed message part
Url : http://lists.bestpractical.com/pipermail/jifty-devel/attachments/20070411/f3e14998/PGP.pgp


More information about the jifty-devel mailing list