realm-java icon indicating copy to clipboard operation
realm-java copied to clipboard

UNIQUE

Open crysan opened this issue 10 years ago • 52 comments

How to determine the class that the field name unique? Just as Primary keys?

crysan avatar Mar 16 '15 07:03 crysan

Yes, so far that's the only way, but we're considering to support some kind of annotation for field value uniqueness

emanuelez avatar Mar 17 '15 11:03 emanuelez

Just to be curious. Do you have a use case for this that isn't already covered by using @PrimaryKey?

cmelchior avatar Mar 17 '15 16:03 cmelchior

The problem was solved. Only after the introduction of a unique field in the table, we had to alter the program logic. There were: realm.beginTransaction(); Authors author = realm.createObject(Authors.class); author.setUrl_base("pptr"); realm.commitTransaction(); Now: Authors author = new Authors(); author.setUrl_base("pptr"); realm.beginTransaction(); realm.copyToRealmOrUpdate(author); realm.commitTransaction(); Very unfortunate that because of one field had to rewrite the code.

crysan avatar Mar 18 '15 00:03 crysan

That happens because you don't set your unique field. If you did you would not have to use standalone objects

emanuelez avatar Mar 18 '15 11:03 emanuelez

Ok.

crysan avatar Mar 19 '15 00:03 crysan

@emanuelez sorry I'm confused, would you mind giving a little code snippet of what you are talking about?

mclark4386 avatar Mar 19 '15 01:03 mclark4386

But I cited above code that used prior to the introduction to the table a unique field, and after it. Now you have to write one line of code to add more new rows to a table.

crysan avatar Mar 19 '15 01:03 crysan

SQLite also has different modes for conflict resolution when it comes to uniqueness constraints we can consider: https://www.sqlite.org/lang_conflict.html

cmelchior avatar Aug 12 '15 10:08 cmelchior

:+1: waiting for this enhancement :)

tarigancana avatar Aug 13 '15 17:08 tarigancana

@beeender @cmelchior Is this feature coming anytime soon?

AlokBansal8 avatar Feb 16 '16 00:02 AlokBansal8

Realm is lacking important feature. realm even has no compound key. so we have to calculate compound key manually.so in practical development, realm is useless. Realm has no roadmap.so don't expect anything.

wyvern610 avatar Feb 16 '16 23:02 wyvern610

@cmelchior now that Primary Keys also imply that the value cannot be changed once persisted, is there a chance for a @Unique constraint which doesn't force you into the "value cannot be changed once persisted" limitation?

Zhuinden avatar Sep 23 '16 08:09 Zhuinden

+1

mfissehaye avatar Sep 29 '16 13:09 mfissehaye

+1

2mwrzesinsky avatar Nov 14 '16 08:11 2mwrzesinsky

+1

the-dr-lazy avatar Nov 22 '16 17:11 the-dr-lazy

+1

YaroslavYrm avatar Jan 03 '17 13:01 YaroslavYrm

Any news on this, I'm still waiting for this feature

lednhatkhanh avatar Mar 15 '17 12:03 lednhatkhanh

+1

shobhitpuri avatar Apr 04 '17 16:04 shobhitpuri

I want to make field 'itemName' of Table Item to be unique in Android Realm. It means 'itemName' should not contain duplicate values. Is there any other way to achieve this except Primary key.. Thanks..

dtmandroid avatar Apr 07 '17 06:04 dtmandroid

+1

ScheNi avatar May 11 '17 15:05 ScheNi

Check is possible reliably in transaction if count > 0

Zhuinden avatar May 11 '17 17:05 Zhuinden

+1

reinaldomoreira avatar May 26 '17 17:05 reinaldomoreira

+1

comm1x avatar Jul 11 '17 22:07 comm1x

+1

lordplagus02 avatar Aug 16 '17 22:08 lordplagus02

+1

zeallat avatar Sep 28 '17 06:09 zeallat

+1

hermamitr avatar Nov 01 '17 22:11 hermamitr

+1

PiWhy avatar Nov 21 '17 14:11 PiWhy

+1

nganthony avatar Jan 31 '18 15:01 nganthony

+1, and i need it on realm-cocoa too.

rudysuharyadi avatar Feb 08 '18 05:02 rudysuharyadi

+1

Ramzi-Alqrainy avatar Feb 15 '18 15:02 Ramzi-Alqrainy