-
Notifications
You must be signed in to change notification settings - Fork 34
Add support for Weak/Strong links aka Cascading deletes #622
Changes from 8 commits
f3a10e3
2c871e1
5012339
f5d05c2
6bdbfdb
96f89f1
8a2a2fc
5616f81
c78dd01
dabdcb7
8cdbb59
0aa34df
8a7fb06
ccf2d9b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,9 +21,11 @@ | |
|
|
||
| #include "util/tagged_bool.hpp" | ||
|
|
||
| #include <string> | ||
|
|
||
| #include <realm/data_type.hpp> | ||
| #include <realm/util/features.h> | ||
|
|
||
| #include <string> | ||
|
|
||
| namespace realm { | ||
| namespace util { | ||
|
|
@@ -58,14 +60,21 @@ enum class PropertyType : unsigned char { | |
| Flags = Nullable | Array | ||
| }; | ||
|
|
||
| enum class Relationship { | ||
| Strong, | ||
| Weak | ||
| }; | ||
| struct Property { | ||
| using IsPrimary = util::TaggedBool<class IsPrimaryTag>; | ||
| using IsIndexed = util::TaggedBool<class IsIndexedTag>; | ||
|
|
||
| std::string name; | ||
| PropertyType type = PropertyType::Int; | ||
| std::string object_type; | ||
| std::string link_origin_property_name; | ||
| // Only used with LinkingObjects. `relationship` is ignored if this is different than "" | ||
| std::string link_origin_property_name = ""; | ||
| // Only useful if the property is Link or LinkList property and `link_origin_property_name` is "" | ||
| Relationship relationship = Relationship::Weak; | ||
| IsPrimary is_primary = false; | ||
| IsIndexed is_indexed = false; | ||
|
|
||
|
|
@@ -74,9 +83,9 @@ struct Property { | |
| Property() = default; | ||
|
|
||
| Property(std::string name, PropertyType type, IsPrimary primary = false, IsIndexed indexed = false); | ||
|
|
||
| Property(std::string name, PropertyType type, std::string object_type, | ||
| std::string link_origin_property_name = ""); | ||
| Property(std::string name, PropertyType type, std::string object_type); | ||
| Property(std::string name, PropertyType type, std::string object_type, std::string link_origin_property_name); | ||
| Property(std::string name, PropertyType type, std::string object_type, Relationship relationship); | ||
|
|
||
| Property(Property const&) = default; | ||
| Property(Property&&) = default; | ||
|
|
@@ -85,6 +94,17 @@ struct Property { | |
|
|
||
| bool requires_index() const { return is_primary || is_indexed; } | ||
|
|
||
| // Return the underlying LinkType. Only useful for Object or Array properties. | ||
| #pragma GCC diagnostic push | ||
| #pragma GCC diagnostic ignored "-Wreturn-type" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Giving |
||
| LinkType link_type() const { | ||
| switch(relationship) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. space between keyword and ( |
||
| case Relationship::Strong: return LinkType::link_Strong; | ||
| case Relationship::Weak: return LinkType::link_Weak; | ||
| } | ||
| } | ||
| #pragma GCC diagnostic pop | ||
|
|
||
| bool type_is_indexable() const; | ||
| bool type_is_nullable() const; | ||
|
|
||
|
|
@@ -204,6 +224,14 @@ inline Property::Property(std::string name, PropertyType type, | |
| { | ||
| } | ||
|
|
||
| inline Property::Property(std::string name, PropertyType type, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This constructor is redundant.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is being used by tests and not having it results in:
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is functionally identical to the three-argument version with a default value for the third argument (i.e. what previously existed).
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those was changed as well, these constructors have no default values anymore as having two 3-argument constructors with different defaults is ambiguous. So there is now a constructor for creating backlinks (with a string default value) and one for creating normal links (with a relationship default value)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, like that. No, your right.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2-arg constructor has been removed |
||
| std::string object_type) | ||
| : name(std::move(name)) | ||
| , type(type) | ||
| , object_type(std::move(object_type)) | ||
| { | ||
| } | ||
|
|
||
| inline Property::Property(std::string name, PropertyType type, | ||
| std::string object_type, | ||
| std::string link_origin_property_name) | ||
|
|
@@ -214,6 +242,16 @@ inline Property::Property(std::string name, PropertyType type, | |
| { | ||
| } | ||
|
|
||
| inline Property::Property(std::string name, PropertyType type, | ||
| std::string object_type, | ||
| Relationship relationship) | ||
| : name(std::move(name)) | ||
| , type(type) | ||
| , object_type(std::move(object_type)) | ||
| , relationship(relationship) | ||
| { | ||
| } | ||
|
|
||
| inline bool Property::type_is_indexable() const | ||
| { | ||
| return type == PropertyType::Int | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -136,6 +136,9 @@ static void compare(ObjectSchema const& existing_schema, | |
| else if (current_prop.requires_index()) { | ||
| changes.emplace_back(schema_change::RemoveIndex{&existing_schema, ¤t_prop}); | ||
| } | ||
| if(target_prop->relationship != current_prop.relationship) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. space between keyword and ( |
||
| changes.emplace_back(schema_change::ChangeRelationshipType{&existing_schema, ¤t_prop}); | ||
| } | ||
| } | ||
|
|
||
| if (existing_schema.primary_key != target_schema.primary_key) { | ||
|
|
@@ -246,6 +249,7 @@ bool operator==(SchemaChange const& lft, SchemaChange const& rgt) | |
| REALM_SC_COMPARE(AddTable, v.object) | ||
| REALM_SC_COMPARE(ChangePrimaryKey, v.object, v.property) | ||
| REALM_SC_COMPARE(ChangePropertyType, v.object, v.old_property, v.new_property) | ||
| REALM_SC_COMPARE(ChangeRelationshipType, v.object, v.property) | ||
| REALM_SC_COMPARE(MakePropertyNullable, v.object, v.property) | ||
| REALM_SC_COMPARE(MakePropertyRequired, v.object, v.property) | ||
| REALM_SC_COMPARE(RemoveIndex, v.object, v.property) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This include was previously in the correct place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not entirely sure why, but If this is not here I get:
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
data_types.hpp needs to include
<cstdint>