Ripple & an attribute named 'key'

Sean Cribbs sean at basho.com
Sat Feb 12 22:58:55 EST 2011


For future reference:
https://github.com/seancribbs/ripple/blob/master/ripple/lib/ripple/document/key.rb

Sean Cribbs <sean at basho.com>
Developer Advocate
Basho Technologies, Inc.
http://basho.com/

On Feb 12, 2011, at 10:56 PM, Mat Ellis wrote:

> Lol. Ripple is wonderful, don't blame us for thinking it's magic ;-)
> 
> Thx this is very helpful.
> 
> M.
> 
> On Feb 12, 2011, at 7:55 PM, Sean Cribbs wrote:
> 
>> Well, when it comes down to it, it's just a method.  There's a lot less magic in Ripple than you'd think. Try this:
>> 
>> def key
>> @key ||= UUID.new # Replace with whatever you want, as long as it's a String
>> end
>> 
>> Sean Cribbs <sean at basho.com>
>> Developer Advocate
>> Basho Technologies, Inc.
>> http://basho.com/
>> 
>> On Feb 12, 2011, at 10:53 PM, Mat Ellis wrote:
>> 
>>> Yep, exactly. But it doesn't appear until I save right? I'd prefer not to have that dependency. Is there a way round?
>>> 
>>> M.
>>> 
>>> On Feb 12, 2011, at 7:51 PM, Sean Cribbs wrote:
>>> 
>>>> If you don't specify a key, Riak will choose one for you (base 62-encoded hash of something, last I checked). Is that not what you're trying to do?
>>>> 
>>>> Sean Cribbs <sean at basho.com>
>>>> Developer Advocate
>>>> Basho Technologies, Inc.
>>>> http://basho.com/
>>>> 
>>>> On Feb 12, 2011, at 10:50 PM, Mat Ellis wrote:
>>>> 
>>>>> The point of the code is not to use a non-string ID but to generate a default. Is it 'failing' because we're attempting to override the type? The actual code in question (this is a simplification) is generating a GUID which can easily be stored as a string instead of an integer. Otherwise we'll just have to use some other term, your example is precisely what we're doing.
>>>>> 
>>>>> Thx
>>>>> 
>>>>> On Feb 12, 2011, at 7:47 PM, Sean Cribbs wrote:
>>>>> 
>>>>>> The choice of "key" as the method/attribute name corresponds to the Riak terminology for the same concept (and is analogous to "id" in ActiveRecord).  If you want to use a non-String value for the key, create a property of some other name and then use the "key_on" method which makes a defined property act as the key.
>>>>>> 
>>>>>> property :some_num, Integer, :presence => true, :default => 1234
>>>>>> key_on :some_num
>>>>>> 
>>>>>> Sean Cribbs <sean at basho.com>
>>>>>> Developer Advocate
>>>>>> Basho Technologies, Inc.
>>>>>> http://basho.com/
>>>>>> 
>>>>>> On Feb 12, 2011, at 8:00 PM, Mat Ellis wrote:
>>>>>> 
>>>>>>> Why do these behave differently in Ripple?
>>>>>>> 
>>>>>>> # Leaves key field blank
>>>>>>> property :key, Integer, :presence => true, :default => 1234
>>>>>>> 
>>>>>>> # Populates key2 field with 1234
>>>>>>> property :key2, Integer, :presence => true, :default => 1234
>>>>>>> 
>>>>>>> We'd like to use the key field as a standard (like the 'id' field is the default in ActiveRecord). Is this a bad idea and if so why?
>>>>>>> 
>>>>>>> M.
>>>>>>> 
>>>>>>> 
>>>>>>> 
>>>>>>> _______________________________________________
>>>>>>> riak-users mailing list
>>>>>>> riak-users at lists.basho.com
>>>>>>> http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com
>>>>>> 
>>>>> 
>>>> 
>>> 
>> 
> 





More information about the riak-users mailing list