Fork me on GitHub

29 Jun 2010

Acyclic relationship validation in Grails

A common domain class use-case is for a self-referential relationship that must not be circular (a directed acyclic graph). For example, a Person class may have a parent property that is a many-to-one relationship with another Person instance. However a given Person cannot be his own parent or ancestor.

We're using just such a relationship for trees of pages that inherit certain characteristics from their ancestors. In order to validate that our users aren't setting up circular references I implemented the following constraint:Then I just needed to register my new constraint by adding ConstrainedProperty.registerNewConstraint(AcyclicConstraint.NAME, AcyclicConstraint) to grails-app/conf/spring/resources.groovy. Using the constraint is as simple as this:
class Person {

    String name
    Person parent

    static constraints = {
        parent acyclic: true
    }
}
The constraint can be mixed with others such as nullable: true. The really nice thing is that the constraint implementation doesn't reference any of my domain classes directly, meaning it can be re-used in any other domain class.

When you're using similar validation logic in multiple classes defining a constraint like this is a much better option than using a validator closure and like many things in Grails it turns out to be pretty easy to implement.

49 comments:

johnrellis said...

awesome! this constraint should definitely be added to the grails source, i reckon it is one that is enforced in all wacky ways in other projects. Adding a constraint looks nice and easy!

dustmite said...

Nice work! Custom constraints in Grails are very powerful. Wonder if this could be extended to look beyond direct relationship and make sure that someone isn't say their own great great grand child or such.

Rob said...

@dustmite it's already doing that

dustmite said...

@Rob Sorry, I noticed that after posting my comment. Really great stuff, took it for a spin last night and works like a charm.

As @johnrellis said this should be included with the Grails source.

Rick Jensen said...

Please, as others have said, get this included in Grails core. It's a sufficiently complex validation that is easy to mess up and is also very common.

cerri bell said...

Jadwal Bola | Permainan Bola | Judi Bola | Taruhan Bola | Agen Bola | Agen Sbobet | Jasa SEO Profesional | Jasa SEO | Harga Jasa SEO Profesional | Jasa SEO Murah | Pakar SEO

Anonymous said...

338a | agen bola | agen sbobet | bola tangkas | casino sbobet | liga champion | prediksi bola | cool mobile gagdet

Anonymous said...

sbobet | ibcbet | agen bola | agen bola Terpercaya | Jasa SEO Profesional | Jasa SEO | Harga Jasa SEO Profesional | Jasa SEO Murah | Pakar SEO

Metamorfosis said...

Pelatihan SDM is network marketing and training information or training an employee who has worked with many consulting firms and training institutions.
pelatihan hrd,
pelatihan pengembangan diri,
pendidikan dan pelatihan sdm,
pelatihan akuntansi keuangan,
pelatihan sales marketing,
pelatihan kehumasan,
pelatihan sdm jogja,
lembaga pelatihan sdm
pelatihan manajemen bisnis,
pelatihan administrasi perkantoran,
lembaga training motivasi,
pelatihan sekretaris,
pelatihan karyawan,
lembaga training di jogja,
pelatihan in house training,
pelatihan public training,
jasa konsultan,
pelatihan pengembangan sdm,
pelatihan manajemen sdm,
program training karyawan,
diklat sdm,
pelatihan sdm untuk rumah sakit,
_____
id card murah,
harga id card,
cetak kartu santri,
produksi id card,
bikin id card,
cetak id card jogja,
id card murah jogja,
cetak id card,
percetakan id card,
pabrik id card,
cetak member card,
cetak kartu pelajar,
cetak kartu siswa,

ssamira Butik said...

I like your stuff, classic right, Now... everything with digital, perdita di peso thanks for remind me for this memories
water heater gainsborough
water heater ariston
water heater rinnai
water heater delizia
water heater wika

Metamorfosis said...

Kursus Arab Pare is a place for all of you who want to study and able to speak arabic. Come and join us..

Tempat Kursus Bahasa Arab

شركات كشف تسربات المياه وعزل اسطح وخزانات said...

شركة تنظيف شقق بجازان
شركة نقل اثاث بجازان
شركة كشف تسربات المياه بجازان
شركة مكافحة حشرات بحائل
تنظيف منازل بحائل
نقل اثاث بحائل
كشف تسربات المياه بحائل

abo-bder said...


شركة شحن عفش من الرياض الي الامارات-دبي
شركة نقل اثاث من الرياض الى الامارات

شركة نقل اثاث من الرياض الى الامارات


Assignment Help said...

I loved the article, keep updating interesting articles. I will be a regular reader… I am offering assignment help to students over the globe at a low price.
Course Mentor
Assignment help
Homework Help
Coursework Help
Become Mentors
how to be a mentor
how to become a mentor
Assignment help
find a mentor
how to get a mentor
how to find a mentor
Coursework Help
Coursework Writing Service
coursework writing help
Homework Help
Help With Homework
Homework Help Service
Assignment help NZ
Assignment help UK
Assignment help US
Assignment help Australia
Assignment help Canada
Assignment help AU

Assignment Help said...

Thanks for sharing this information. I have shared this link with other keep posting such information to provide best in class law assignment help online at very affordable prices.

Assignment help
Assignment help
Assignment help
Python Programming Assignment
Programming Assignment Experts
Assignment help tutors
Assignment help

Assignment Help said...

I loved the article, keep updating interesting articles.and we serve best food according to our customers' reviews we have a specious hall for marriages & special arrangement for kitty parties and other parties. You can visit us at any time we would love to serve you.

assignment help
assignment help
online assignment help
assignment help online
assignment help australia
do my assignment
college assignment help
university assignment help
statistics assignment help
finance assignment help

Assignment Help said...

I love the article keep updating article. And we serve best food according to our customer’s review we have a specious hall for marriage & special arrangement for kitty parties and other parties. You can visit us at any time we would love to serve you.
Assignment help Australia
Australian Assignment Help
Assignment writing service Australia
Online assignment help australia
Assignment Help Brisbane
Assignment help Sydney
Assignment Help Adelaide
Assignment Help Perth
Assignment Help Melbourne
Assignment Help Canbera
Essay Writing Service australia
Nursing Assignment Help Australia
University Assignment Help Australia
Write My Essay Australia
Cheap Essay Writing Service Australia
Accounting Assignment Help Australia

Assignment Help said...

I found this one pretty fascinating and it should go into my collection. Very good work! I am Impressed. We appreciate that please keep going to write more content. We are the assignment helper, we provide services all over the globe. We are best in these:- services
dm beginners
dm beginner
digital marketing for website
digital marketing for beginner
digital marketing beginner
learn digital marketing
learn digital marketing free online
learn digital marketing free
learn seo
how to learn affiliate marketing
dm beginners
dm beginner
digital marketing for website
digital marketing for beginner
digital marketing beginner
learn digital marketing
learn digital marketing free online
learn digital marketing free
learn seo
how to learn affiliate marketing

Assignment Help said...


Many of the people are depressed about the problems of essay writing. Well, don’t worry about that because we are providing this service at a very reasonable price.

Statistics Assignment Help
Statistics Homework Help
statistics help
statistics homework
statistics homework helper
SPSS Help
SPSS Tutors
SPSS Homework Help
matlab homework help
matlab assignment help
help with matlab
stata homework help
probability assignment
probability assignment help
R Programming homework help
Bio Statistics Assignment Help
R Programming Help
R Programming homework help
business statistics assignment help
business statistics homework help

Assignment Help said...

I loved the article, keep updating interesting articles.and we serve best food according to our customers' reviews we have a specious hall for marriages & special arrangement for kitty parties and other parties. You can visit us at any time we would love to serve you.

Article Assignment Help
Essay Assignment Helper
Essay writing
Essay writing service
Dissertation help
Thesis writing help
Write My Essay
Do My Essay
Hire Cheap Essay Writer
College Essay Help

Assignment Help said...

I love the article keep updating article. And we serve best food according to our customer’s review we have a specious hall for marriage & special arrangement for kitty parties and other parties. You can visit us at any time we would love to serve you.
" Essay writing
"
Essay Writer
seo writing service
Essay writing service
Essay writing help
Write My Essay
hire seo writer
hire writer
Write my essay cheap
hire article writer

Assignment Help said...

I love the article keep updating article. And we serve best food according to our customer’s review we have a specious hall for marriage & special arrangement for kitty parties and other parties. You can visit us at any time we would love to serve you.
Assignment Help
Assignment Helper
Essay writing
Essay writing service
Dissertation help
Thesis writing help
Write My Essay
Computer Science Assignment Help
Assignment Help South Africa
Assignment Writing Service

Assignment Help said...

I loved the article, keep updating interesting articles. I will be a regular reader… I am offering assignment help to students over the globe at a low price.
verdant marriage palace
verdant Resort
marriage palace in Pehowa
Wedding Venue in Pehowa
Banquet Hall in Pehowa
Resort in Pehowa
Best Resorts near Pehowa
Best marriage palace in Pehowa
Best Family Restaurant in Pehowa
Best Veg Restaurant in Pehowa
Best Non-Veg Restaurant in Pehowa
Chawlas 2

james cook said...

It is nice to read such high-quality content. It is a good article that discusses the topic at hand quite well. I am looking forward to read more articles from your site. Keep up the good work.
assignment help uk

Hailie Hills said...

At what type of exam questions I need to pay attention more? I'm sure that at least once every student asks him/herself this question. I can recommend you to pay attention to the facts, people names, differences, and similarities. Those things will help you to recover information which you prepared before.

Puremelda said...

Many students are undecided about the best nursing research paper help Company to deal with due to the high number of companies that offer similar services.

Rebeca Thomson said...

Hello, thanks for this interesting article. I appreciate it a lot. Luckily I did my paper, with the help of this source https://essayelites.com/buy-a-capstone-project-online and now I can have some free time by reading this amazing blog post.

Alley John said...



Are you students and do not know How to write an assignment
? So do not worry about writing a good assignment because MyAssignmentHelp is providing the best assignment writing expert's for students.

acmarket said...




Thankyou for the valuable information.iam very interested with this one.
looking forward for more like this.

https://www.advnt01.com/5-ways-to-build-enterprise-mobile-apps-the-right-way/
https://www.asmallcinema.org/do-you-need-to-know-everything-about-hybrid-app-development/

https://www.cfecgc-unsa-ft-orange.org/top-6-mistakes-app-entrepreneurs-make-during-app-development-and-marketing/
https://www.theliyakebedefoundation.org/fun-and-practical-tablet-apps-for-seniors/
https://www.capriles.tv/not-all-apps-are-created-equal/






Marriot Roy said...



Connect with UAE VAT Expert for get best vat software in uae for vat return filing from professional expert’s at affordable price.

myassignmenthelpau said...

This post is not just informative but impressive also. The post is so convincing that it created an urge to choose Nursing Assignment Help services. You can email us at cs@Myassignmenthelpau.Com or Phone Number: +61-2-8005-8227

rickypauls said...

Great write-up! All doubts regarding Assignment Help solved after reading the post. Sometimes, it becomes difficult to manage the time for writing homework due to some unavoidable reasons. I have recommendation for website greatassignmenthelp for ordering best writing services to complete your academic task.
Assignment Helper
Assignment Help Online
Online Assignment Help
Assignment Help Online Services
Assignment Assistance
Assignment Help Experts
Assignment Writing Help

shashi said...

Ignouproject offer the guide books and project to the learners of the university students. Our website help those students who are working and don't have time to write their Ignou project. To help these learners we have project writing experts who write plagiarism free project which is totally customized according to the students.

meldaresearch said...

We assure you that all the best essay writers online, custom college papers, research papers and term papers that we deliver to our clients are the best in the industry and you do not need to have a second thought when buying any of our cheap paper writing service from us.

Ideal Assignment Help said...

A very high level post with a knowledgeable information .thanks you for giving me such a nice information. If you need any college level Assignment Help at reliable quality with better work. Kindly visit Ideal assignment help.

Rayan Warner said...

While working excellent the day I bring Microsoft office 365 into play, suddenly from the last couple of days, it started to throw some error while working in it. However, after taking Office 365 Support and reading the measures which are mentioned in this guide helps me to resolve my entire issues related to Microsoft 365. Get support click here
Office 365 Help
Office 365 Support
Microsoft Office 365 Support
Outlook Support
Microsoft Outlook Support
Outlook Support Number
Outlook Support Phone Number
Outlook Tech Support Phone Number
Outlook Technical Support Phone Number
Outlook Customer Service Phone Number
Outlook Customer Support Phone Number
Outlook Support Number
Microsoft Office Support
Microsoft Office Customer Service
Microsoft Tech Support
Microsoft Tech Support Number
Microsoft Tech Support Phone Number
Microsoft Technical Support Phone Number
Microsoft Technical Support Number
Microsoft Technical Support
Microsoft Office Support Phone Number
Microsoft Office Support Number

kiara Jess said...

Thank you so much for sharing this post, I appreciate your work.It was a great informative post.Go so many useful and informative links. Loved your writings also. Concept of the topic was well discussed. Love to come here again. We also provide affordable MBA Assignment help in uk.

jonas cruz said...

Thanks for sharing this information. We need such information to create CDR Reports. You can get complete CDR Report Writing Service from us. We also provide CDR Reports in Australia, Summary Statement Writing and Career Episode Writing.

ireland assignment help said...

I read this blog post and this is a really good post, so thanks a lot for sharing this good blog post, I hope to keep more post for sharing. thanks once again. assignment writer

James Wright said...

The writing experts will help the students to compose the dissertations. If you are currently looking an online dissertation help service for writing a master's dissertation proposal that can make the process of writing and submission easier, then consider working with MyAssignmentHelp - the no.1 academic writing help portal in Malaysia.

Alpha Assignment Help said...

I can only imagine how much research has gone into this. I like your writing skills as it makes one feel included in the journey. Thank you for the valuable notes.
Assignment Help
Dissertation Writing Services
Essay Writing Service
Marketing Assignment Help
Finance Assignment Help
Management Assignment Help
Cheap Assignment Help
Assignment Help Uk
Best Dissertation Writing Services
Account Assignment Help
Get Assignment Help
Assignment Help Usa
Economics Assignment Help
Academic Writing Help
accounting assignment writing service
cheap assignment writing service
get assignment help online
best assignment help online
best online assignment help

myassignmenthelp said...

My Assignment help is an incomparable online assignment help company delivering excellent academic assignments, essays, coursework and reports. Through a team of over 3000 subject experts we ensure individual attention to every student making the assignment help experience completely personalized in nature. With our round the clock services, you can be assured of high grades every time.

Alpha Assignment Help said...

I can only imagine how much research has gone into this. I like your writing skills as it makes one feel included in the journey. Thank you for the valuable notes.
Assignment Help
Dissertation Writing Services
Essay Writing Service
Marketing Assignment Help
Finance Assignment Help
Management Assignment Help
Cheap Assignment Help
Assignment Help Uk
Best Dissertation Writing Services
Account Assignment Help
Get Assignment Help
Assignment Help Usa
Economics Assignment Help
Academic Writing Help
accounting assignment writing service
cheap assignment writing service
get assignment help online
best assignment help online
best online assignment help

Expo 2020 said...

I know this is one of the most meaningful information for me. And I'm animated reading your article. But it's a good thing, the website is perfect; the articles are great. Thanks for the tone of tangible and possible help.
Skydive dubai

Keith Morris said...

I am a freelancer and have been helping a lot of students in providing assistance to students who frequently gets worried about their assessment tasks and went online to search for australia assignment help terms. We at My Assignment Services have potentially recognised the need way back and started what we are an enlarged version of then. With many assignment helper companies in the market, no one has quite able to match the standard that we follow. We give utmost priority to students by strictly adhering to the assignment requirements as well as marking rubrics to score high grades. Our Assignment uk assignment help writers are well-proficient in not only comprehending your assessment tasks but also to give an expertise finish to it. Provided a well-written assignment suitable to your needs, your search for professional essay writers will now end with My Assignment Services. You just have to visit our website for more information.

meldaresearch said...

One of the things that you will realize is that our company offers custom Nursing Research Papers for Sale that are similar to what you desire for you to improve your grade. Our writing urgency has specialized in offering Term Papers Writing Services, and we have been in the industry for a decade.

onlineassignmnet said...

I read the article, this is awesome. Keep updating interesting articles. I am offering assignment help to students over the globe at very affordable prices.
statistics assignment help
econommics assignment help
finance assignment help

ravi said...

top 10 apps in india
Best Pirate Bay Alternatives
Free Movie Apps for Android
Free Movie Apps for iPhone

Academic Assignment Writing said...

Hello, I have browsed most of your posts. This post is probably where I got the most useful information for my research. Thanks for posting, we can see more on this. Are you aware of any other websites on this subject.
Dissertation Writing Services