我有以下非正规化数据结构: 一个联系人可以关联多个记录。一个记录可以有多个关联的联系人(许多< - >很多关系)。为了跟踪他们的关系,一个int值来表示一个特定的记录联系人的角色,角色值存储在两个独立的参考FirebaseIndexRecyclerAdapter - 如何从键参考位置获取每个键的值?
Contact
- Contact1:data
- Contact2:data
- Contact3:data
Record
- Record1:data
- Record2:data
Record_Role_Ref
- Record1
-- Contact1: roleA
-- Contact2: roleA
-- Contact3: roleD
- Record2
-- Contact1: roleB
Contact_Role_Ref
- Contact1
-- Record1: roleA
-- Record2: roleB
我使用FirebaseIndexRecyclerAdapter是显示相关的联系人到列表一个特定的记录ID。因此,对于关键的参考,我会用Record_Role_Ref/RECORD_ID,并为数据参考我会用联系,就像这样:
// Setup the reference to the all the associated contact list in record_role_ref, using the record id as key
Query mRecordRoleRef = firebaseDatabase.getReference().child(DB_RECORD_ROLE_REF).child(mRecordId);
// Reference the Contact data ref
Query mContactRef = firebaseDatabase.getReference().child(DB_CONTACT);
FirebaseIndexRecyclerAdapter mContactAdapter = new FirebaseIndexRecyclerAdapter<Contact, ContactViewHolder>(Contact.class,
R.layout.item_contact,
ContactViewHolder.class,
mRecordRoleRef, // The Firebase database location containing the keys associated contacts to this record
mContactRef)// The Firebase database location to watch for data changes. Each key key found at keyRef's location represents a list item in the RecyclerView.
限制(S):我不希望将角色值存储在每个联系人都并记录对象,因为每当角色发生更改时,联系人和记录的整个对象都会被提取和更新。用户想要删除,修改,移动联系人和记录,并更改角色。
问题: 联系人的角色值作为密钥的值存储在mRecordRoleRef中。 FirebaseIndexRecyclerAdapter是否可以/如何从关键引用中获取值?在这种情况下,什么是好的/最好的做法?
感谢提前:)