On Jueves, 24 de Marzo de 2011 17:24:48 mikelb escribió: > I like the idea of trying the OrderedHash. Where would I start > looking into that?
I have never used it, searching for orderedhash to guess how to create and sort it, I have found elements are yielded by each in the order they were inserted in the hash. So you should build the OrderedHash sorting the hash by start date. > > Thanks, > M > > On Mar 4, 3:11 am, "Sergio Cambra .:: entreCables S.L. ::." > > <[email protected]> wrote: > > On Jueves, 3 de Marzo de 2011 19:19:06mikelbescribió: > > > Hey all, > > > > > > How is this currently working in AS? I have a subform that allows > > > the editing of the sub-item and the creation of a new item > > > simultaneously. In what order does that take place? I would like it > > > to perform the Updates FIRST and then do the creates in order of > > > creation. Here's why: > > > > > > The subform looks like this: > > > > > > Price StartDate EndDate > > > > > > > $13 2/12/2010 [5/15/2010] > > > > > > [$20] [5/16/2010] [ ] > > > > > > The ">" indicates an existing record and the [ ] indicates fields that > > > are being edited/created. > > > So the first record ($13) is an existing one, and it starts with a > > > NULL EndDate (basically meaning that the price is valid forever). The > > > user wants to go up and close out that price (adding in 5/15/2010 as > > > the new EndDate) and create a new Price at the same time. > > > > > > Now, I have a validation in place that makes sure that dates don't > > > overlap. Date's would overlap for a number of reasons, but in this > > > case, for some reason, the CREATE is taking place first, and since it > > > has a NULL EndDate and the old record *also* has a NULL EndDate, it > > > views that as overlapping and the validation fails. > > > > > > If, however, the UPDATE were to take place first, the old record would > > > be updated with an EndDate that would occur *before* the StartDate of > > > the new record, and validation would succeed. > > > > Values are sent as a hash, but hash has no order, so order of updates and > > creates is not defined. > > > > You could try converting hash to orderedhash in the controller, although > > I haven't used it and I don't know how to sort. > > > > Or trying to move the validation to the parent object. Don't checking > > overlapping of date ranges belong to parent model? Parent object can > > check children before saving them and it will check it after setting all > > children with new values. > > > > > Thoughts/help? > > > > > > MANY THANKS!! > > > M > > > > -- > > Sergio Cambra .:: entreCables S.L. ::. > > Mariana Pineda 23, 50.018 Zaragoza > > T) 902 021 404 F) 976 52 98 07 E) [email protected] -- Sergio Cambra .:: entreCables S.L. ::. Mariana Pineda 23, 50.018 Zaragoza T) 902 021 404 F) 976 52 98 07 E) [email protected] -- You received this message because you are subscribed to the Google Groups "ActiveScaffold : Ruby on Rails plugin" 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/activescaffold?hl=en.
