On Dec 3, 5:43 pm, "Dan Kubb (dkubb)" <[EMAIL PROTECTED]> wrote:
> Hi Sergey,
>
> > For example, I have one to one association like that
>
> > Role
> > has 1, :user
>
> > User
> > belong_to :role
>
> > Is not having methods like role.build_user & role.create_user a bug or
> > a feature?
>
> That's an interesting idea. At first glance I'd say that this is
> cleaner:
>
> # role is a Role instance
> role.user = User.create(attributes)
>
> However, the problem with this is that the user object needs to have
> it's FK set, which by default would be role_id if the PK of Role was
> id. So it means that first the user is created with a nil role_id,
> and then it will need to be updated when the role object is saved.
> This seems a bit clumsy to me. So in order for the above to work,
> you'd need to go:
>
> role.user = User.new(attributes)
> role.user.save # or just role.save
>
> Which also seems clumsy.
Isn't this consistent with Dirkjan's comment here -
http://groups.google.com/group/datamapper/msg/9b3a757e548862f5
and your own remarks here -
http://groups.google.com/group/datamapper/msg/d5f4de90c76d7080
Mark.
If the role was saved then I would want to
> just be able to create a user in one-step, so a Role#create_user
> method might be useful. I don't see much point in a Role#new_user (or
> Role#build_user) except maybe for consistency -- in those cases I
> would most likely use role.user = User.new which to me seems more
> straight forward.
>
> We can take this under consideration in the dkubb/dm-core branch, as
> we're currently rewriting the underlying code. The API is pretty much
> staying the same in dkubb/dm-core, although there are a few minor
> changes (that have the required deprecation warnings). These are only
> really are coming about because now that we're examining the API for
> the specs and docs we've found some flaws and inconsistencies and are
> trying to correct them with the least amount of disruption to deployed
> code.
>
> Dan
> (dkubb)
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---