java - (ORMLite - android) Setting foreign key fields directly -
in android app, pull down record server , save them db - i'd able save "message" records without having first save "thread" records attached to.
a message composed of:
- string id
- string body
- long sent_ts
- string sender_id
- string topic_id
is possible set topic_id , sender_id records directly on message object rather creating dummy topic instance , user instance? know can either not mark fields foreign , give on easier lookups of related objects or save nested objects first, possible directly set foreign key references in case keys externally provided?
this being done on android standard android sqlite setup.
edit
i settled on writing multiple models on same database table. it's not elegant solution, seemed way able either populate foreign id fields directly or join on other tables, depending on context.
i'd able save "message" records without having first save "thread" records attached to.
so each message
has foreign topic
, user
fields, , you'd persist message
instances before you've assigned them foreign objects?
yes, can leave topic
, user
fields null
. need mark them canbenull=true
of course. later should able set topic
or user
fields on message
in question , call messagedao.update(message)
update database.
edit:
after reading comments understand. there way save id fields onto class instead of creating dummy objects have id field set? there answer no unless raw sql create statement yourself. ormlite needs have topic
field because that's expecting. if want id can have int topic_id
field instead of topic topic
, topic association yourself.
Comments
Post a Comment