Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
kasim1011 opened this issue Apr 4, 2016 · 18 comments
Closed
Assignees

Comments

@kasim1011
Copy link
Contributor

kasim1011 commented Apr 4, 2016

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.

@georgebester
Copy link

I found this on google
chech fomating at time of creating the table
http://stackoverflow.com/questions/31368994/android-database-sqlite-sqliteexception-no-such-table-users-table-code-1

can you please post the code you used to create the attendance_report_hr_attendance_rel

@georgebester
Copy link

or this
Change Your DataBase Version Or 2.First Uninstall Your Apps In the Emulator or Phone And Re-install Your Apps. I In This way Think Your Problem Will be solved

@kasim1011
Copy link
Contributor Author

@saltracker This framework handles entire database for me. it's the feature of this framework.
I've tried uninstallation than reinstallation of the app. I've done that twice before posting issue.

@georgebester
Copy link

which one have you done

@kasim1011
Copy link
Contributor Author

@saltracker I've updated my previous comment. please, have look.

@georgebester
Copy link

It is reported that "after upgrading from Android Studio 2.0 beta 4 to beta 6, that SugarRecord tables are not being created through fresh app install, database migration through version change, database migration through database name change and all other methods."

They say it is to do with the 'Instant Run' feature as disabling this seems to resolve the issue

I am not sure if there is anything that can be done by Sugar resolve this, but as it is likely to crop up in future, I believe it should be added to the README or associated documentation to warn others.

chennaione/sugar#542

@georgebester
Copy link

disable instant run and confirm if it makes a difference

@kasim1011
Copy link
Contributor Author

@saltracker I've created demo app dedicated to this issue for you. please have a look

@georgebester
Copy link

thanks ive checked it out it and will study it

@kasim1011
Copy link
Contributor Author

@saltracker It's my pleasure.

@georgebester
Copy link

Hi kasim

Thanks I've got it loaded.
Do you have  a demo user and password ?

Sent from BlueMail

On 4 Apr 2016, 14:59, at 14:59, Kasim Rangwala notifications@github.com wrote:

@saltracker It's my pleasure.


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub:
#138 (comment)

@dpr-odoo
Copy link
Collaborator

dpr-odoo commented Apr 5, 2016

Hello @kasim1011,

It seems enhancement in ORM for inserting relation record from main record values.
Current version not supporting direct record insert for relation model. You can add id list for many to many but for one to many it is not available yet. That is the reason system show error and crashed and orm going to find table for that column that actually does not exists. (i.e., your one to many column)

The solution available soon.

@dpr-odoo dpr-odoo self-assigned this Apr 5, 2016
@kasim1011
Copy link
Contributor Author

Hello @dpr-odoo

Thanks a lot for your positive reply.

@georgebester
Copy link

yes i see what you mean 

@kasim1011
Copy link
Contributor Author

Hello @saltracker

Thanks

@georgebester
Copy link

could the problem exist because of the way the attendance is being reported ie normally one person with one phone reports on their individual attendance - but what we want to do is for one supervisor to report on many teachers and learners (One to many ) ?

@dpr-odoo
Copy link
Collaborator

Improved and merged to master (48c8bf9)

  • Fixed sync issues
  • Performance improved
  • Minor bug fixes.

Documentation for handling relation records: http://mobile.odoo.co.in/v2/getting-started/working-with-odoo-mobile/components/working-with-relation-records.html

@akash567
Copy link

akash567 commented Apr 6, 2017

I have just started exploring this framework.But I am facing one issue.I am not able to understand that from where the customers data is coming,when we click on customer side menu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants