I''ve got a production pipeline for our visual fx stuff that I"m working on and the flow down from parent to child is project sequence shot element (w/ versioning) Sequences are three letter acronyms. I want to be able to do validates_uniqueness_of for that field, but on a project by project basis. e.g. in Project "movie 1" there can only be one sequence with a value of "OPN" but there can be "OPN" in another project. Since it validates against all entries in the table, how do I limit this? is this the :scope => attribute? or is this something else? -- John Athayde bobo-8WfjrGkLNeNByuSxxbvQtw@public.gmane.org Meticulous | www.meticulous.com (work) Rotoscope | www.rotoscope.com (sound: rock band) Boboroshi & Kynz | www.boboroshiandkynz.com (sound: electronic) Personal Weblog | www.boboroshi.com (play) "Those who would give up essential Liberty, to purchase a little temporary Safety, deserve neither Liberty nor Safety." - Benjamin Franklin (1706-1790) Reply of the Pennsylvania Assembly to the Governor November 11, 1755 _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
> e.g. in Project "movie 1" there can only be one sequence with a value of > "OPN" but there can be "OPN" in another project. > Since it validates against all entries in the table, how do I limit > this? is this the :scope => attribute? or is this something else?Yes :) In models/sequence.rb: validates_uniqueness_of :name, :scope => ''project_id'' Warning: It falls down a little if the ''scoped'' field can be NULL: you can have two identically-named children with NULL parents. I''ve coded up a workaround based on the library version of validates_uniqueness_of that can cope with NULL parents; I can supply that if anyone''s keen. - M
Matt - Thanks :) I guess a secondary question is: in that parent child chain, is there inheritance? e.g. I don''t have to specify that the grandparent (as it were) is the grandparent in an element, as it assumes that the parent of the parent is the grandparent? in use: an element is in sequence OPN shot 101 (grandparent and parent respectively). do i need to add a constraint for sequence to element, or just shot, and then shot have a constraint for sequence, and sequence one for project, etc. On Jul 18, 2005, at 6:05 PM, Matt Powell wrote:>> e.g. in Project "movie 1" there can only be one sequence with a >> value of "OPN" but there can be "OPN" in another project. >> Since it validates against all entries in the table, how do I >> limit this? is this the :scope => attribute? or is this something >> else? >> > > Yes :) > > In models/sequence.rb: > > validates_uniqueness_of :name, :scope => ''project_id'' > > Warning: It falls down a little if the ''scoped'' field can be NULL: > you can have two identically-named children with NULL parents. I''ve > coded up a workaround based on the library version of > validates_uniqueness_of that can cope with NULL parents; I can > supply that if anyone''s keen. > > - M > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > >-- John Athayde bobo-8WfjrGkLNeNByuSxxbvQtw@public.gmane.org Meticulous | www.meticulous.com (work) Rotoscope | www.rotoscope.com (sound: rock band) Boboroshi & Kynz | www.boboroshiandkynz.com (sound: electronic) Personal Weblog | www.boboroshi.com (play) "Those who would give up essential Liberty, to purchase a little temporary Safety, deserve neither Liberty nor Safety." - Benjamin Franklin (1706-1790) Reply of the Pennsylvania Assembly to the Governor November 11, 1755 _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Hi John, > in that parent child chain, is there inheritance? e.g. I don''t have to > specify that the grandparent (as it were) is the grandparent in an > element, as it assumes that the parent of the parent is the grandparent? I guess the short answer is that since the parent''s ID will be unique, and no sequence will belong to more than one shot (right?), then you get that behaviour by default. Is that what you mean? - M
the opposite, but yes. an element will belong to one shot (at least for now) a shot will belong to one sequence a sequence will belong to one project. On Jul 18, 2005, at 6:26 PM, Matt Powell wrote:> I guess the short answer is that since the parent''s ID will be > unique, and no sequence will belong to more than one shot (right?), > then you get that behaviour by default. > > Is that what you mean?-- John Athayde bobo-8WfjrGkLNeNByuSxxbvQtw@public.gmane.org Meticulous | www.meticulous.com (work) Rotoscope | www.rotoscope.com (sound: rock band) Boboroshi & Kynz | www.boboroshiandkynz.com (sound: electronic) Personal Weblog | www.boboroshi.com (play) "Those who would give up essential Liberty, to purchase a little temporary Safety, deserve neither Liberty nor Safety." - Benjamin Franklin (1706-1790) Reply of the Pennsylvania Assembly to the Governor November 11, 1755 _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails