wood burning stoves 2.0*
The moose likes Groovy and the fly likes Grails associations Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Groovy
Bookmark "Grails associations" Watch "Grails associations" New topic
Author

Grails associations

Maharaj thak
Greenhorn

Joined: Jul 29, 2010
Posts: 27
Hi All,
I have two classes Job and Recruiter which I have modelled thus..

class Job{

String description

static belongsTo=Recruiter

}


class Recruiter{
String name

static hasMany=[jobs:Job]

}


How can I delete the jobs that are more than 7 days old?

Regards
Maharaj Thak
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Unless you have a Date associated to Jobs, you can't. If you do and you're just omitting that bit of code, then I suggest posting more code and then we can see what needs to be done.


GenRocket - Experts at Building Test Data
Maharaj thak
Greenhorn

Joined: Jul 29, 2010
Posts: 27
Hi Greg,
Thanks for the reply.I think I didn't ask the question the right way.Recruiter has many Jobs posted.So anytime I delete a Recruiter,the associated jobs get deleted as well.But what if i only want to delete particular jobs(e.g. all the jobs posted in the last 7 days) without deleting the Recruiter.


Regards
Maharaj Thak
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Well, again, you don't have a Date defined in your Job class. But I'll pretend you do. First, you have to determine how old a particular job is. If it is within the bounds of your timeframe, then just do:

 
Don't get me started about those stupid light bulbs.
 
subject: Grails associations
 
Similar Threads
sorting collection on fields of associated object?
THREAD
Is These Sun Certification is Worth while
return statement
How can I be overqualified???