Skip to content

Why framework is looking for relation table for inserting OneToMany record. #138

@kasim1011

Description

@kasim1011

I've two Models called HrAttendance and AttReport. here's they are:

public class AttReport extends OModel {

    public static final String TAG = AttReport.class.getSimpleName();

    OColumn lat = new OColumn("Latitude", OFloat.class);
    OColumn lng = new OColumn("Longitude", OFloat.class);
    OColumn employee_id = new OColumn("Name", HrEmployee.class,
            OColumn.RelationType.ManyToOne);

    OColumn date_reported = new OColumn("Date Reported", ODate.class);
    OColumn date_reporting = new OColumn("Date Reporting", ODateTime.class);
    OColumn hr_attendance_ids = new OColumn("Order Lines", HrAttendance.class,
            OColumn.RelationType.OneToMany)
            .setRelatedColumn("attendance_report_id");

    public AttReport(Context context, OUser user) {
        super(context, "attendance.report", user);
    }
}


public class HrAttendance extends OModel {

    public static final String TAG = HrAttendance.class.getSimpleName();

    OColumn employee_id = new OColumn("Name", HrEmployee.class,
        OColumn.RelationType.ManyToOne);
    OColumn name = new OColumn("Date", ODateTime.class);
    OColumn state = new OColumn("State", OSelection.class)
            .addSelection("sign_in", "Sign In")
            .addSelection("sign_out", "Sign Out");
    OColumn attendance_report_id = new OColumn("Name", AttReport.class,
            OColumn.RelationType.ManyToOne);

    public HrAttendance(Context context, OUser user) {
        super(context, "hr.attendance", user);
    }

}

Now, when I'm attempting to insert data in AttReport table. framework says no such table: attendance_report_hr_attendance_rel

here's code:

AttReport report = new AttReport(getContext(), user());
JSONArray hrAttendanceIDs = new JSONArray()
        .put(8)
        .put("2016-04-03 15:28:30")
        .put("sign_in");
OValues values = new OValues();
values.put("lat", 0f);
values.put("lng", 0f);
values.put("date_reported", "2016-04-03");
values.put("employee_id", 8);
values.put("hr_attendance_ids", hrAttendanceIDs);

Log.e(TAG, "Values before inserting: " + values.toString());
Log.e(TAG, "newID" + report.insert(values));

here's the Log:

E/Employees: Values before inserting: {hr_attendance_ids=[8,"2016-04-03 15:28:30","sign_in"], date_reported=2016-04-03, lat=0.0, employee_id=8, lng=0.0}
I/AccountManagerService: getTypesVisibleToCaller: isPermitted? false
E/SQLiteLog: (1) no such table: attendance_report_hr_attendance_rel // <--This one
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
                  Process: com.serpentcs.saltracker, PID: 4500
                  android.database.sqlite.SQLiteException: no such table: attendance_report_hr_attendance_rel (code 1): , while compiling: DELETE FROM attendance_report_hr_attendance_rel WHERE attendance_report_id = ?
                      at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
                      at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:887)
                      at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:498)
                      at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
                      at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
                      at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
                      at android.database.sqlite.SQLiteDatabase.delete(SQLiteDatabase.java:1496)
                      at com.odoo.core.orm.OModel.storeManyToManyRecord(OModel.java:953)
                      at com.odoo.core.orm.provider.BaseModelProvider.storeUpdateRelationRecords(BaseModelProvider.java:253)
                      at com.odoo.core.orm.provider.BaseModelProvider.insert(BaseModelProvider.java:166)
                      at android.content.ContentProvider$Transport.insert(ContentProvider.java:263)
                      at android.content.ContentResolver.insert(ContentResolver.java:1231)
                      at com.odoo.core.orm.OModel.insert(OModel.java:799)
                      at com.odoo.addons.employees.Employees.onViewCreated(Employees.java:119)
                      at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1086)
                      at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252)
                      at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
                      at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)
                      at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:517)
                      at android.os.Handler.handleCallback(Handler.java:739)
                      at android.os.Handler.dispatchMessage(Handler.java:95)
                      at android.os.Looper.loop(Looper.java:148)
                      at android.app.ActivityThread.main(ActivityThread.java:5417)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

I can't figure out what's going on. any kind of help or suggestions are welcome.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions