Hi
Just looking for a fews pointers on the best way of building and
validating trees of objects from a hash of values (ie when a form
posts). Its pretty straightforward to do when there is no validation,
however when there is, and it fails on a parent object you can no
longer add children to its association because it requires a primary
key.
This mean the tree from that point down doesn't get built so I can't
redirect to a form to show the errors.
For example..
params = {
'foo' => {
'0' => {
'none_empty_field' => ""
'bar' => {
'0' => { 'thing' => '4' }
'1' => { 'thing' => '4' }
},
...
}
}
class Foo < Sequel::Model
one_to_many :bars
def validate
validates_presence :none_empty_field
end
end
class Bar < Sequel::Model
many_to_one :foo
end
params[:foo].each do |k,v|
foo = Foo.new(v['none_empty_field]')
foo.raise_on_save_failure = false
foo.save # fails validation because of mission field
v[:bar].each do |k,v|
foo.bars << Bar.new(v) # this will fail because the foo instance
has no primary key
end
end
Will fail when you try to add the associations.
Any help would be appreciated :)
Mike
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sequel-talk" 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/sequel-talk?hl=en
-~----------~----~----~----~------~----~------~--~---