requiring unique rows on a joining table with rails
Having figured this problem in rails all by myself made me so happy that I wanted to write it down and not let myself forget.
Problem
I have a One-to-Many table relationship and the many table needs to have each record have a different value for the field of "letter" for parent row created.
Solution
By using the validates_uniqueness_of in the model of the child table and defining the scope. The validation will limit the check of an existing row to a smaller range.
Example
validates_uniqueness_of :letter, :scope => :parent_field_id
Going Further
I had another problem that required the use of validates_uniqueness_of but it required checking a value for a field that had a true/false value. I needed to have many rows exist with the field being false, but onle one row contain true. The following validation works very good for this situation:
validates_uniqueness_of :is_correct, :scope => :parent_column_id, :if => Proc.new { |answer| answer.is_correct }
The scope limits the validation of the child row to be localized for the parent record only when the :if statement executes the block contains the "is_correct" field.
What I like about this statement is that the if block can be any type of check you want. For example if you want to check on a different field than the one you are deciding is unique on.
Closing
Please be aware this is the only way I know how to accomplish this task. If you have any suggestions on how to accomplish what I described above please add your comments below.
container house from puma
This is one the two designs I have found on the net that look freaking awesome for living.
architecture and hygiene – old lady house
I dont agree with the name of this house but I am happy that I found some plans to draw ideas off and start illustrating my house made from containers. I think my next step would be to make some drawings and also talk to an architect to see how much land I would need and build a quick estimate of how much this entire project would cost.
Dont forget your tooth brush
When traveling, don't forget your tooth brush. Also, go to the website called don't forgetyourtoothbrush.com and it will email what you should pack. I am going to try this as soon as I get home!
Converting Steel Shipping Containers to Housing
ISBU's are recycling America. Reusing the steel containers that are not being used while taking up space on the shipping yards storage area. But people have been using them for building them into a house. I am thinking this is a really good idea for the following reasons:
- No trees used
- Cheaper materials (20% to 50% overall)
- Reusing extra containers
- Modular
I am looking around for plans and pictures of existing ISBUs but have not found any. But I like this idea.
Searching around the net I found some sources of info:
- http://www.containerarchitecture.co.nz/
- Converting Steel Shipping Containers to Housing - BobVila.com
- http://firmitas.org/
- http://www.bdcnetwork.com/article/CA6517769.html
- http://www.hybridseattle.com/
- http://weburbanist.com/2008/08/25/buying-designing-and-building-cargo-container-homes/
- http://www.shippingcontainers.com/newcontain.htm
Books
Not container related, but freaking cool













