Created
          November 9, 2009 19:14 
        
      - 
      
- 
        Save kalupa/230185 to your computer and use it in GitHub Desktop. 
    Example of doing a Table-less ActiveRecord
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | class Foo < Tableless | |
| column :bar, :string | |
| validates_presence_of :bar | |
| end | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | class Tableless < ActiveRecord::Base | |
| def self.columns | |
| @columns ||= []; | |
| end | |
| def self.column(name, sql_type = nil, default = nil, null = true) | |
| columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default,sql_type.to_s, null) | |
| end | |
| # Override the save method to prevent exceptions. | |
| def save(validate = true) | |
| validate ? valid? : true | |
| end | |
| end | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment