File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,19 @@ public function setMeta($key, $value = null) {
45
45
46
46
protected function setMetaString ($ key , $ value ) {
47
47
$ key = strtolower ( $ key );
48
+
49
+ // If there is a default value, remove the meta row instead - future returns of
50
+ // this value will be handled via the default logic in the accessor
51
+ if (
52
+ property_exists ( $ this , 'defaultMetaValues ' ) &&
53
+ array_key_exists ( $ key , $ this ->defaultMetaValues ) &&
54
+ $ this ->defaultMetaValues [$ key ] == $ value
55
+ ) {
56
+ $ this ->unsetMeta ( $ key );
57
+
58
+ return $ this ;
59
+ }
60
+
48
61
if ( $ this ->getMetaData ()->has ( $ key ) ) {
49
62
50
63
// Make sure deletion marker is not set
Original file line number Diff line number Diff line change @@ -176,6 +176,16 @@ public function testDefaultMetaValues() {
176
176
177
177
$ this ->assertNull ( $ metaData ->first (), 'Default value should be removed from database. ' );
178
178
179
+ $ user ->setMeta ( 'default_meta_key ' , 'foo ' );
180
+ $ user ->save ();
181
+
182
+ $ this ->assertEquals ( 'foo ' , is_null ( $ meta = $ metaData ->first () ) ? null : $ meta ->value , 'Default value should be changed in database. ' );
183
+
184
+ $ user ->setMeta ( 'default_meta_key ' , 'default_meta_value ' );
185
+ $ user ->save ();
186
+
187
+ $ this ->assertNull ( $ metaData ->first (), 'Default value should be removed from database. ' );
188
+
179
189
$ user ->delete ();
180
190
}
181
191
You can’t perform that action at this time.
0 commit comments