The new one is obviously failing a validation on the user or
user_preference . Check the object for any validation errors.

On Mon, Dec 8, 2014 at 3:31 PM, Frederick Cheung <[email protected]
> wrote:

>
> On Monday, December 8, 2014 8:48:37 AM UTC, Man Vuong Ha Thanh wrote:
>>
>>
>> But, if I call that method again, it will delete the `profile` record.
>>
>> $ user.create_user_preference
>>
>>    (0.3ms)  BEGIN
>>   User Load (0.8ms)  SELECT  "users".* FROM "users"  WHERE "users".
>> "deleted_at" IS NULL AND "users"."id" = $1 LIMIT 1  [["id",
>> "055df158-4b3f-43f0-b73a-0c14e0ba7723"]]
>>   UserPreference Exists (0.7ms)  SELECT  1 AS one FROM "user_preferences"
>>  WHERE "user_preferences"."user_id" = '055df158-4b3f-43f0-b73a-
>> 0c14e0ba7723' LIMIT 1
>>    (0.3ms)  ROLLBACK
>>    (0.2ms)  BEGIN
>>   SQL (0.4ms)  DELETE FROM "user_preferences" WHERE "user_preferences".
>> "id" = $1  [["id", "9eb6cabd-7c50-4f2b-8562-1159e1c2f4b4"]]
>>    (37.0ms)  COMMIT
>>
>> It looks weird for me. Is it a normal behaviour, or am I doing something
>> wrong??
>>
>
> Well the delete makes sense to me - you're creating a new user preference,
> so the old one should be destroyed since this is a has_one and you've
> configured the relationship as dependent: :destroy. Not sure why it doesn't
> create a new one though
>
> Fred
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/rubyonrails-talk/7ecc668a-6ba5-40bc-8628-16f151e99b89%40googlegroups.com
> <https://groups.google.com/d/msgid/rubyonrails-talk/7ecc668a-6ba5-40bc-8628-16f151e99b89%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/CAFKVRj8n_ynWAdW4dHy5hbysgMfr%2Bphq%2B3a7bRJcTGFjsDkNdQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to