A quick and dirty fix... There must be a better way to get the belongs_to 
types proplist though...

 diff boss_db_adapter_mongodb_old.erl boss_db_adapter_mongodb.erl 
492c492
<                     unpack_value(AttrName, MongoValue, ValueType)
---
>                     unpack_value(Type, AttrName, MongoValue, ValueType)
547c547
< unpack_value(_AttrName, [H|T], _ValueType) when is_integer(H) ->
---
> unpack_value(_, _AttrName, [H|T], _ValueType) when is_integer(H) ->
549c549
< unpack_value(_AttrName, {_, _, _} = Value, datetime) ->
---
> unpack_value(_, _AttrName, {_, _, _} = Value, datetime) ->
551,565c551,568
< unpack_value(AttrName, Value, ValueType) ->
<     case is_id_attr(AttrName) and (Value =/= "") of 
<         true -> 
<             IdType = id_type_from_foreign_key(AttrName),
<             unpack_id(IdType, Value);
<         false -> 
<             boss_record_lib:convert_value_to_type(Value, ValueType)
<     end.
< 
< id_type_from_foreign_key(ForeignKey) ->
<     Tokens = string:tokens(atom_to_list(ForeignKey), "_"),
<     NameTokens = lists:filter(fun(Token) -> Token =/= "id" end, 
<         Tokens),
<     string:join(NameTokens, "_").
< 
---
> unpack_value(RecordType, AttrName, Value, ValueType) ->
>     case is_id_attr(AttrName) and (Value =/= "") of
>       true ->
>               
BelongsToTypes=RecordType:belongs_to_types(boss_record:new(RecordType,[])),
>               
AttrNameAtom=list_to_atom(string:join(lists:reverse(tl(lists:reverse(string:tokens(atom_to_list(AttrName),
 
"_")))),"_")), % drop _id from the end
>               case proplists:get_value(AttrNameAtom,BelongsToTypes) of
>                       undefined ->
>                               unpack_id(atom_to_list(AttrNameAtom),Value)
>                               ;
>                       RealAttrType->
>                               unpack_id(atom_to_list(RealAttrType),Value)
> 
>               end
>               ;
>       false ->
>               boss_record_lib:convert_value_to_type(Value, ValueType)
>     end
> . 


On Saturday, January 3, 2015 11:20:25 PM UTC+1, mpeter wrote:
>
> It is obviously the unpack_id(_,_) fun that messes up things in 
> boss_db_adapter_mongodb.erl. It should respect the model defined by 
> belongs_to_<model> when unpacking the id.
>
> On Saturday, January 3, 2015 11:02:22 PM UTC+1, mpeter wrote:
>>
>> Dear All,
>>
>> Sorry for not getting back earlier - notification did not came that it 
>> has been answered.
>> The problem is still present and very easy to reproduce.
>> Assume the following simple use case.
>> We have foo and bar. bar has an owner and a manager.
>>
>> -module(foo,[Id,Name]).
>> -----
>> -module(bar,[Id, OwnerId, ManagerId]).
>> -belongs_to_foo(owner).
>> -belongs_to_foo(owner).
>> ------------
>> simple test code with Mongo:
>> í{ok,{_,Id,_}}=(foo:new(id,"name")):save().
>> {ok,{_,Id2,_,_}}=(bar:new(id,Id,Id)):save().
>> B=boss_db:find(Id2).
>> B:owner().
>> B:manager().
>>
>> the boss_db:find will rturn the object with changed (useless) ids. This 
>> is a serious problem which makes it impossible to have multiple belongs_to 
>> associations to the same type.
>>
>> Is there a solution to overcome this?
>>
>>
>> Thanks,
>> Best,
>> Peter
>>
>> On Thursday, January 17, 2013 8:08:08 PM UTC+1, Holocene wrote:
>>>
>>> On Sat, Jan 5, 2013 at 12:45 PM, mpeter <[email protected]> 
>>> wrote: 
>>>
>>> > If I add a new greeting with a specific user id, it gets saved 
>>> properly, but 
>>> > the value in the OwnerId column changes from usr-1 usr-2 etc to 
>>> oner-1, 
>>> > owner-2 etcwhen saved. 
>>> > 
>>>
>>> The belongs_to(usr) in your model is superseding the belongs_to(owner) 
>>> somehow. Either that, or the variable where you are passing in the 
>>> OwnerId is being assigned to UsrId instead of OwnerId 
>>>
>>>
>>>
>>>
>>> -- 
>>> -- 
>>> Sam Rose 
>>> Hollymead Capital Partners, LLC 
>>> Cel: +1-(517)-974-6451 
>>> email: [email protected] 
>>> http://hollymeadcapital.com 
>>> http://p2pfoundation.net 
>>> http://socialmediaclassroom.com 
>>>
>>> "The universe is not required to be in perfect harmony with human 
>>> ambition." - Carl Sagan 
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"ChicagoBoss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
Visit this group at http://groups.google.com/group/chicagoboss.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/chicagoboss/19913ce5-3936-41f2-aaa4-8fa111654425%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to