Re: Better Support for Mapping Table (many to many) checking

11 views
Skip to first unread message

Igor Polevoy

unread,
Jan 22, 2015, 5:01:08 PM1/22/15
to activejd...@googlegroups.com
Gina, the method:

Patient.belongsTo(Doctor.class)

is to test relationship between  models, while what you want:

if (Patient.belongsTo (iDoctorId)) 
        doStuff();

makes little sense, as the iDoctorId is certainly related to an instance of Doctor model, and yet you are trying to see if it is related to a Patient model, not an instance of patient class!

I think what you want is this:

patient.belongsTo(doctor);

That would make more sense

tx

On 01/22/2015 01:17 AM, Gianna Giavelli wrote:
If I have Class Patient and Class Doctor, mapped via a many to many join table that has both IDs, I like the syntax where you can say:


Patient.belongsTo(Doctor.class)

The problem is, most of the time I have just ONE of the classes and an ID. So rather than re-write a full on query pointing to the mapping table, it would be nice to be able to specify with one class and an ID for the other. 

  int  iDoctorId = 20;

  if (Patient.belongsTo (iDoctorId)) 
        doStuff();

I think is more common pattern of use and saves the redundent doctor lookup to get 2 objects. What do you suggest? 


--
You received this message because you are subscribed to the Google Groups "ActiveJDBC Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to activejdbc-gro...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Gianna Giavelli

unread,
Jan 23, 2015, 2:26:02 AM1/23/15
to activejd...@googlegroups.com
In my defense, I think i was consfused by the documentation example (see below) which uses .class. I guess really what I want to do is take my object instance of patient and doctor and then do if (patient.belongsTo(doctor))

my point is... this forces me to do another lookup of the second object, when it is more typical to just have the ID laying around. 

Checking for association

This is pretty simple:

System.out.println(Patient.belongsTo(Doctor.class));//prints "true"

Igor Polevoy

unread,
Jan 25, 2015, 12:57:54 PM1/25/15
to activejd...@googlegroups.com
Gianna, I just do not follow your question. What are you trying to do?

tx
Reply all
Reply to author
Forward
0 new messages