Wouldn't doing so disallow you from manually setting the ID? I know it's a
weird case but we do this in our product in a table with string IDs.

On Fri, Aug 21, 2015 at 5:07 AM, masa331 <do...@uol.cz> wrote:

> Hi guys,
>
> this is code from ActiveRecord::Persistance:
>
> def _create_record(attribute_names = self.attribute_names)
> attributes_values = arel_attributes_with_values_for_create(attribute_names
> )
>   new_id = self.class.unscoped.insert attributes_values   self.id ||=
> new_id if self.class.primary_key
>   @new_record = false   id end
>
> I'm curious about the rational behind line no. 5. Why we set `self.id` to
> value returned from db only if it was previously empty? I couldn't find any
> test nor some discussion. Also the code dates back to 2011.
>
> I work with some legacy db where primary key is string which is modified
> in some database trigger. Because the `self.id` is set before save it
> isn't assigned to proper value returned from db after trigger modification.
>
> I can't think of any problem if we always assign id to value returned from
> database.
>
> I would love to create PR if it's ok
>
> thanks!
>
> Sledujte náš blog.uol.cz, facebook.com/uol.cz, gplus.to/uolcz
> <http://facebook.com/uol.cz>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Core" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to rubyonrails-core+unsubscr...@googlegroups.com.
> To post to this group, send email to rubyonrails-core@googlegroups.com.
> Visit this group at http://groups.google.com/group/rubyonrails-core.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
*Kevin D. Deisz*
*TrialNetworks* - part of DrugDev
Software Developer
383 Elliot Street, Suite G
Newton, MA 02464
+1 617.952.4071 x134 (office)
+1 703.615.0396 (mobile)
kde...@trialnetworks.com

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-core+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

Reply via email to