0

I'm new to Groovy/Grails so this could be an easy question. I have the feeling this is common code but I've spent a while and I can't find the right thing to Google.

I have a domain structure with several many to many relationships ( indicated by <--> )

Worker <--> Assembly Line <--> Part

The trick is that there are also 2 different one to many relationships on the same class...

Worker -> Inspection Part -> Inspection

A part can be inspected many times, but there always has to be a person who does the inspection.

I'm in the Assembly Line controller and and I can do AssemblyLine.get(id) easy enough, but that will give me all inspections for the parts in that line. I only want the inspection for the worker that I pulled from the session.

Is there an easy way to do this that I'm missing? It feels like there should be.

Bob McNees
  • 371
  • 5
  • 11

1 Answers1

0

Simply use GORM, like

Inspection.findAllByWorkerAndPart(session.worker,somePart)

If you need more specific, please write down the domain classes with related properties.

Thanks.

Shafiul
  • 1,452
  • 14
  • 21
  • This would only give me the parts that were inspected, right? I want to start with an Assembly Line and display all of the parts on that line, not just the ones that were inspected by a worker. – Bob McNees May 02 '13 at 12:50
  • Aha..this would give all the inspections not part. Actually which collection do you need? If you need parts then you can use: ` Parts.findAllByAssemblyLineAndWorker(assemblyLine, worker) ` . Can give better suggestion if you share your domains and share which collections do you require. – Shafiul May 02 '13 at 14:56
  • I need the information starting with the Assembly Line. Currently the code is written AssemblyLine.get(params.id). This almost works, except it returns every inspection whereas I want to limit the inspections included. – Bob McNees May 02 '13 at 18:34
  • I can post more code later, but currently I'm at work and since this is a personal project I don't have the code available on this machine. – Bob McNees May 02 '13 at 18:35