Why framework is looking for relation table for inserting OneToMany record.
kasim1011 opened this issue · 18 comments
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.
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
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
@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.
which one have you done
@saltracker I've updated my previous comment. please, have look.
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.
disable instant run and confirm if it makes a difference
@saltracker I've created demo app dedicated to this issue for you. please have a look
thanks ive checked it out it and will study it
@saltracker It's my pleasure.
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)
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.
yes i see what you mean
Hello @saltracker
Thanks
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 ) ?
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
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