Re: Can't Delete From Mapping Table (when no column is named ID)

17 views
Skip to first unread message

Igor Polevoy

unread,
Jan 25, 2015, 10:30:09 PM1/25/15
to activejd...@googlegroups.com
ActiveJDBC depends on ID columns for deletes, updates and relationships. If you do not have IDs, then you will need to write custom SQL.
I suggest to add ID, because it is cheap anyway.



On 01/23/2015 01:16 AM, Gianna Giavelli wrote:
I'm trying to delete the mapping table entry between 2 tables. 

Say I have Boys and Dogs

so I have a mapping table

MTBL_BOYS_DOGS
   BOYID INT,
   DOGID INT


So I try to delete from it but I cant after looking up the object and calling Delete, because there is no ID column

I don't want an id column because to me, these are both foreign keys

So how do I do this?

MtblBoyDog oMtblBoyDog = MtblBoyDog.findFirst("BOYID=? and DOGID=?", strBoyId, strDogID);
        if (oMtblBoyDog != null)
        oMtblBoyDog.delete();

org.javalite.activejdbc.DBException: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Unknown column 'id' in 'where clause', Query: DELETE FROM mtbl_boy_dog WHERE id= ?, params: null
--
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.

Message has been deleted

Gianna Giavelli

unread,
Feb 10, 2015, 6:28:40 PM2/10/15
to activejd...@googlegroups.com
My mistake was using MTBL (mapping tables) as a direct object from the standpoint of ActiveJDBC.

Instead, I used the add and remove, which works WITHOUT ID column in the mapping table. I do for both add and remove. Here is code for remove: works fine without ID. Took me a bit to realize you don't treat a mapping table as direct model class its "hidden". If you DO need to do so, then yes ad an ID column. 

        Category oCategory = Category.findById(strCatId);
    User     oUser     = User.findById(strUserId);
    if (oCategory == null || oUser == null)
    System.out.println ("nulls!");
    else
    oCategory.remove(oUser);
Reply all
Reply to author
Forward
0 new messages