Android Question swap a record in a one to one relation

Cenny

Active Member
Licensed User
Longtime User
Hi,

I have two tables, 'Models' with a primary key Model_id and the second 'Devices' with primary key Device_id and foreign key Model_id.
The two tables have a one-to-one relation, that is to say that every model has only one device and that device can only be tied to one model.
The question is, how can I swap an existing device to another existing model?

Cenny
 

josejad

Expert
Licensed User
Longtime User
Hi:

I don't know if I'm missing something, but you should change the foreign key Model_id in the Devices table to point another Model_Id.
 
Upvote 0

Cenny

Active Member
Licensed User
Longtime User
exactly, but I cannot simply allocate the device to another model, because that model has already a relation to a device
 
Last edited:
Upvote 0

josejad

Expert
Licensed User
Longtime User
Sorry, I don't know if my answer solve your question or if you knew it but you don't know how to do it...
 
Upvote 0

Cenny

Active Member
Licensed User
Longtime User
I don't know how to do it, because, in my opinion I have to make two changes in one go
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User

Read through this:

https://www.sqlite.org/foreignkeys.html#overview

RBS
 
Upvote 0

emexes

Expert
Licensed User
How do you add new entries to the tables? Presumably the same issue should arise then, but there is some mechanism to work around it. Can the same workaround mechanism be used here?
 
Upvote 0

emexes

Expert
Licensed User
thanks, but I was not that far yet
No worries (I think). Always good to spot potholes in the road ahead so you can go around them rather than through them

I would have expected that the database transaction would only enforce restrictions (like one-to-one-ness) at the end of the transaction, and look the other way regarding any interim temporary transgressions.

But all my B4A data stuff so far has just been straight text files, so I'm possibly making unwarranted assumptions here.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…