> Perhaps if you give us a little more information on A and B, their
> attributes etc., I can offer a little more advice?
>

Well, what I am trying to achieve here is that no way two records are
created in B such that they belong to same record in A. For clear
explanation let me try to map the problem in more realistic way. Let's
say

A => Student {roll_no}
B => Marksheet ( maths, science, sst, student_id )

Now every student has only one marksheet. I want to make sure that for
every student only one mark sheet is created. For this I have
maintained a relationship of 1:1 between STudent:Marksheet. Marksheet
blongs_to Student and Student has_one marksheet.

Marksheet also has a field student_id. And
<<<<validates_uniqueness_of :student_id >>.>>will ensure that no two
records are created in a normal situation.

But I am concerned of a rare possibility when through two different
sessions same user is trying to create two marksheets.
Based on my understanding in such cases, this validation might allow
to create two records with the same "stident_id" if in both the
sessions database is fetched when no record was saved.

My approach was to not even to let the user create the record in
Marksheet/  As soon as a Student record is created, I add the
Marksheet record as well. Now I can create and save marksheet record
in normal case but if Marksheet record has validations for NIL fields
( to be left NIL initially for subject fields ) will fail the
validation.

Is it the situation where "locks" are used ??
vipin

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" 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/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to