branching on first_or_create

40 views
Skip to first unread message

manu

unread,
Aug 19, 2012, 6:18:06 AM8/19/12
to datam...@googlegroups.com
Hello

I'm trying to branch based on the return value of first_or_create, but something eludes me.

flight = Flight.first_or_create({:avatar_id => avatar.id, :mission_id => mission.id} , {:monture_id => monture.id:role_id => role.id:temps_vol => params[:temps_vol], :statutfinmission_id => statut.id})

When the user submits a new Flight entry, I first check if an entry already exists (using the table's composite key avatar.id + mission.id).

But as I understand it, flight will always return true, whether it creates a new record or finds one already existing. Is this correct? Is there anyway to differentiate between the two cases?

Thx a bunch.

Arthur M. Meskelis

unread,
Sep 4, 2012, 11:02:59 AM9/4/12
to datam...@googlegroups.com
well, from the api http://rubydoc.info/gems/dm-core/1.1.0/DataMapper/Model:first_or_create it will always return a object model. So, you would have to do a find first.

2012/8/19 manu <etab...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "DataMapper" group.
To view this discussion on the web visit https://groups.google.com/d/msg/datamapper/-/uhx12rVuVrwJ.
To post to this group, send email to datam...@googlegroups.com.
To unsubscribe from this group, send email to datamapper+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.



--
------------------------------------------
 1. Notebook para você ficar livre e programar a vontade: R$ 2300
 2. Curso de Programação/SysAdmin/DBA: R$ 5000
 3. Pedir a solução pronta para um problema numa lista de discussão: Não tem preço !

E para todas as outras existe RTFM, STFW e  LMGTFY

manu

unread,
Sep 19, 2012, 9:52:25 AM9/19/12
to datam...@googlegroups.com
Oh, yeah, thanks Arthur. What was I thinking... :/
Reply all
Reply to author
Forward
0 new messages