0

I am trying to join a few tables in swift using the SQLite.swift library and I am having a few problems. The below code shows the issue:

I first join the tables:

    let ext_tasks = tasks.join(tasktypes, on: tasktypes[tty_id] == tasks[task_type])
        .join(preUsers, on: preUsers[Worker_ID] == task_ownerID)
        .order(task_dueDate)
        .filter(task_ownerID == iUserID)

At this point I have the tables joined and all the fields from tasks, task types and preUsers are there properly.

Following I run the second join statement:

    let ext_equipment = equipment.join(equipment_type, on: equipment_type[eqt_id] == equipment[equ_type])
        .join(facilities, on: facilities[fac_id] == equipment[equ_facid])
        .join(eqowners, on: eqowners[Worker_ID] == equipment[equ_owner])
        .order(equ_make)
        .filter(equ_status >= 0)

Again, after running this statement I can access all the fields from the equipment, equipment_type, facilities and eqowners tables, up to here everything is working as expected...

However then I try to join the two above results using:

    let comp_tasks = ext_tasks.join(ext_equipment, on: ext_equipment[equ_id] == ext_tasks[task_eqID])
        .order(task_dueDate)

Here is where I run into a problem, it seems like the tables coming from the ext_tasks query are there but only the equipment table from the ext_equipment query is available.

Further when I try to access the "facilities"."facility_name" field, I get the following message saying that the field does not exist:

fatal error: no such column '"Facilities"."Facility_Name"' in columns:

["Equipment"."EquipmentType_ID", "Equipment"."Equipment_ID", "Equipment"."Equipment_Owner_ID", "Equipment"."Facility_ID", "Equipment"."Status", "PreUsers"."Client_ID", "PreUsers"."Date_LastLogin", "PreUsers"."First_Name", "TaskTypes"."TaskType_ID", "TaskTypes"."Type", "Tasks"."Equipment_ID", "Tasks"."Owner_ID", "Tasks"."Priority", "Tasks"."Time_Complete", "Tasks"."Time_Start"]:

(I removed some of the columns in there to shorten the answer, there are 53 fields in total shown) but as you can see only tables from the first join + the equipment table are shown, the joins from the second query (equipment_type, facilities and eqowners) are nowhere to be seen

I would appreciate if someone could let me know why this is happening, this has been killing my brain for hours and I just can't figure it out...

Thanks in advance!

zzpaf
  • 73
  • 7
  • This could be a bug.Your query is complex enough that it may not generate properly right now. Can you try opening an issue on GitHub with enough information to reproduce? – stephencelis May 23 '15 at 15:48
  • As a workaround, I did change the joining strategy, instead of joining two (already joined) queries, I just kept adding one additional join after another and make the query larger, less efficient as I had to go through 5 joins to get where I wanted but got it solved. Thanks Stephen for the comment, I will open a bug in github – zzpaf May 23 '15 at 15:58

0 Answers0