Validation of aggregates

This may not be possible…

I have an aggregation of clwholename defined in my model.

the aggregation builds clwholename from :first_name, middle_initial,
last_name

and it generally works fine.

I am trying to add a validation so while there may be many ‘John’
first_names, and ‘Doe’ last_names, I only want one ‘John D.’

so I tried…

validates_uniqueness_of :clwholename

and I get an error when I try to save a new record that it can’t find
the clwholename column which I thought was the point of using the
aggregation in the first place.

Is is possible to ‘validate’ on an aggregation?

Craig

Craig W. wrote:

Is is possible to ‘validate’ on an aggregation?

You’ll have to code both the DB uniqueness check and
the error adding into a “validate” method.


We develop, watch us RoR, in numbers too big to ignore.

On Sat, 2006-03-04 at 19:58 +1100, Mark Reginald J. wrote:

Craig W. wrote:

Is is possible to ‘validate’ on an aggregation?

You’ll have to code both the DB uniqueness check and
the error adding into a “validate” method.


I’m gathering that’s because the clwholename ‘aggregation’ doesn’t exist
until the record is written (client.save has completed) and the
validation must come before.

I think I got it.

thanks

Craig

On Sun, 2006-03-05 at 01:49 +1100, Mark Reginald J. wrote:

for uniqueness. You have to do the search on all its component fields.


that sort of means that an aggregation is not a fully baked proposition
and perhaps I should just have a column in my table named for the
aggregation so the aggregation is saved separately - so I can avoid some
the the gymnastics that I have to do in various places such as
validation and ‘auto_complete’

Does this make sense?

Craig

Craig W. wrote:

that sort of means that an aggregation is not a fully baked proposition
and perhaps I should just have a column in my table named for the
aggregation so the aggregation is saved separately - so I can avoid some
the the gymnastics that I have to do in various places such as
validation and ‘auto_complete’

Yes, full support for validating aggregated attributes is not yet
in Rails. It could be added, automatically searching for a
conjunction of components for the uniqueness test, and using to_s,
to_i, or custom methods in the aggregation class to carry out
other validations.

Stick with your aggregation. Let it handle what it can handle,
and manually do the other stuff. Even without the aggregated
name you’d still have to write a custom uniqueness test.


We develop, watch us RoR, in numbers too big to ignore.

Craig W. wrote:

On Sat, 2006-03-04 at 19:58 +1100, Mark Reginald J. wrote:

You’ll have to code both the DB uniqueness check and
the error adding into a “validate” method.

I’m gathering that’s because the clwholename ‘aggregation’ doesn’t exist
until the record is written (client.save has completed) and the
validation must come before.

No, it exists. It’s just not a database field that can be searched
for uniqueness. You have to do the search on all its component fields.


We develop, watch us RoR, in numbers too big to ignore.

On Sun, 2006-03-05 at 11:32 +1100, Mark Reginald J. wrote:

conjunction of components for the uniqueness test, and using to_s,
to_i, or custom methods in the aggregation class to carry out
other validations.

Stick with your aggregation. Let it handle what it can handle,
and manually do the other stuff. Even without the aggregated
name you’d still have to write a custom uniqueness test.


thank you for the clear explanation

Craig