util::Optional<Property> ObjectStore::property_for_column_index(ConstTableRef& table, size_t column_index) { StringData column_name = table->get_column_name(column_index); #if REALM_ENABLE_SYNC // The object ID column is an implementation detail, and is omitted from the schema. // FIXME: Consider filtering out all column names starting with `!`. if (column_name == sync::object_id_column_name) return util::none; #endif if (table->get_column_type(column_index) == type_Table) { auto subdesc = table->get_subdescriptor(column_index); if (subdesc->get_column_count() != 1 || subdesc->get_column_name(0) != ObjectStore::ArrayColumnName) return util::none; } Property property; property.name = column_name; property.type = ObjectSchema::from_core_type(*table->get_descriptor(), column_index); property.is_indexed = table->has_search_index(column_index); property.table_column = column_index; if (property.type == PropertyType::Object) { // set link type for objects and arrays ConstTableRef linkTable = table->get_link_target(column_index); property.object_type = ObjectStore::object_type_for_table_name(linkTable->get_name().data()); } return property; }
ObjectSchema::ObjectSchema(const Group *group, const std::string &name) : name(name) { ConstTableRef table = ObjectStore::table_for_object_type(group, name); size_t count = table->get_column_count(); properties.reserve(count); for (size_t col = 0; col < count; col++) { Property property; property.name = table->get_column_name(col).data(); property.type = (PropertyType)table->get_column_type(col); property.is_indexed = table->has_search_index(col); property.is_primary = false; property.is_nullable = table->is_nullable(col) || property.type == PropertyType::Object; property.table_column = col; if (property.type == PropertyType::Object || property.type == PropertyType::Array) { // set link type for objects and arrays ConstTableRef linkTable = table->get_link_target(col); property.object_type = ObjectStore::object_type_for_table_name(linkTable->get_name().data()); } properties.push_back(std::move(property)); } primary_key = realm::ObjectStore::get_primary_key_for_object(group, name); set_primary_key_property(); }