Android Question swap a record in a one to one relation

Discussion in 'Android Questions' started by Cenny, Jul 5, 2019.

  1. Cenny

    Cenny Member Licensed 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
     
  2. José J. Aguilar

    José J. Aguilar Active Member Licensed 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.
     
  3. Cenny

    Cenny Member Licensed User

    exactly, but I cannot simply allocate the device to another model, because that model has already a relation to a device
     
    Last edited: Jul 5, 2019
  4. José J. Aguilar

    José J. Aguilar Active Member Licensed 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...
     
  5. Cenny

    Cenny Member Licensed User

    I don't know how to do it, because, in my opinion I have to make two changes in one go
     
  6. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    Read through this:

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

    RBS
     
  7. emexes

    emexes Well-Known Member 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?
     
  8. Cenny

    Cenny Member Licensed User

    thanks, but I was not that far yet
     
  9. emexes

    emexes Well-Known Member Licensed User

    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.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice