Just a thought. Maybe you can use a call back before the record is
saved to set up a virtual attribute based on the result of new_record?
On Jan 5, 3:52 am, Fabrice Fabrisss li...@ruby-forum.com wrote:
hello,
find_or_create_by has a different behaviour according to the existence
of the
Fabrice Fabrisss wrote in post #972422:
hello,
find_or_create_by has a different behaviour according to the existence
of the instance in the database,
is it possible to know the resulting operation (find or create) which
has been actually executed ?
Why do you care? What's your use case?
Thank you for your answers,
I like the solution with the 'initialize' function but I still haven't
tried it.
I have a counter which counts the number of new occurence I will insert
in the database, that's why I want to be able to distinguish both cases,
Sincerely,
Fabrice
--
Posted via
Please quote when replying.
Fabrice Fabrisss wrote in post #972838:
Thank you for your answers,
I like the solution with the 'initialize' function but I still haven't
tried it.
I have a counter which counts the number of new occurence I will insert
in the database, that's why I want to be
With find_or_create, I don't believe there is a way.
You can certainly do it with find_or_initialize
winter = Tag.find_or_initialize_by_name(Winter)
winter.persisted? # true if record exists, false if it does not
--
You received this message because you are subscribed to the Google Groups
5 matches
Mail list logo