On Nov 8, 2011, at 10:58 AM, [email protected] wrote:
> Also, if I run this:
>
> Radcheck.find(23).groupnames << Group.find(6)
OK, here we go. You need to remove the #groupnames accessor you added to
Radcheck; it has no value and is just confusing the situation.
In DataMapper, you associate resource instances with each other by adding them
to relationship collections. Try this:
```
u = Radcheck.get(23)
g = Group.get(16)
u.radgroups << g
```
That will create a join record associating the given Radcheck and Group
instances. If you want to associate a Radcheck instance with a collection of
Groups, you might try:
```
class Radcheck
…
def group_ids=(ids)
new_groups = Group.all(:id.in => ids) # step 1
radgroups.replace(new_groups) # step 2
end
end
```
The core thing here is 1) finding the groups identified by the given IDs and 2)
replacing the Groups associated with the Radcheck.
Hope that helps,
Emmanuel
> NoMethodError: You have a nil object when you didn't expect it!
>
> Even though both commands on their own work fine.
>
> On Nov 8, 6:12 pm, Emmanuel Gomez <[email protected]> wrote:
>> On Nov 8, 2011, at 2:08 AM, [email protected] wrote:
>>
>>> Thanks yoda.
>>
>>> The suggestion's not working with group_ids either
>>
>> Which suggestion? What did you do with group_ids?
>>
>>> I'll ask the same elsewhere. Thanks
>>
>> I know my tone was flippant, perhaps even condescending, but despite
>> appearances, I am trying to help :). I you gave me a bit more information,
>> I'd be in a better position to help.
>>
>> Or you can ask elsewhere,
>> Emmanuel
>
> --
> You received this message because you are subscribed to the Google Groups
> "DataMapper" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/datamapper?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"DataMapper" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/datamapper?hl=en.