README.md in auto_build-0.4.3 vs README.md in auto_build-0.5.0
- old
+ new
@@ -38,10 +38,20 @@
auto_build :address, :phone,
To initialize several fields. One `after_initialize` callback will be created per association.
+### belongs_to associations
+
+Works the same as the `has_one` association:
+
+ class User
+ belongs_to :directory
+
+ auto_build :directory
+ end
+
### has_many associations
You can automatically initialize a `has_many` association in the same way you initialized a `has_one`
association:
@@ -90,9 +100,21 @@
* **Watch out for fields with `reject_if`**. Since the AutoBuild callback will be added as an
`after_initialize` hook this might overwrite the validations done in `reject_if`.
* The option `:append => true` is equivalent to `:count => 1`.
* None of the operations will overwrite existing objects.
+Autobuilding associations means that if there's a value in the column, the object **will be loaded
+every time you load the parent**. This is problematic if you're trying to optimize your code. To get
+a better picture of this:
+
+ class User
+ has_one :address
+ auto_build :address
+ end
+
+If you do `User.select(:id)` the resulting query will be `SELECT id FROM users;` **plus** `SELECT *
+from addresses WHERE user_id = 42";`. This happens because we're calling calling `user#address`
+every time we initialize a `User` object.
How it works
----
`auto_build` works by adding an `after_initialize` callback **per association** to your model.