Created
August 8, 2008 00:52
-
-
Save radar/4527 to your computer and use it in GitHub Desktop.
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 Address < ActiveRecord::Base | |
| belongs_to :suburb | |
| belongs_to :thing, :polymorphic => true | |
| end | |
| Fields: | |
| thing_id | |
| thing_type | |
| suburb_id |
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 Client < ActiveRecord::Base | |
| has_one :address, :as => :thing, :dependent => :destroy | |
| end | |
| Fields: | |
| name |
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 Employer < ActiveRecord::Base | |
| has_one :address, :as => :thing, :dependent => :destroy | |
| end | |
| Fields: | |
| name |
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
| Finding a suburb with a postcode of "5114", and getting all the employers. |
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 Suburb < ActiveRecord::Base | |
| has_many :addresses | |
| end | |
| Fields: | |
| id | |
| name | |
| postcode |
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
| SQL statement: | |
| SELECT employers.* FROM `suburbs`, `addresses`, `employers` WHERE suburbs.postcode = "5114" AND suburbs.id = addresses.suburb_id AND addresses.thing_id = employers.id and addresses.thing_type = 'employer'; | |
| Oops, could call this with #find_by_sql and it does exactly as it should. Yuji's the man. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment