Glad You're Ready. Let's Get Started!

Let us know how we can contact you.

Thank you!

We'll respond shortly.

Standup 09/26/2008: proxy_target vs load_target

Interesting Things

  • When defining an extension to an association, you can access the loaded association data through proxy_target. If the data hasn’t been preloaded/loaded when you call this method, it will return []. If you’d like to manually load the target, you can call load_target, and you can call loaded to determine if the proxy data has been loaded. For most situations, however, you can rely on the association to load itself when necessary by calling methods on self as follows:
has_many :people do
  def bad_people {|person| person.bad? }

  # exact same situation as 'bad_people', but 2x worse code
  def good_people
    load_target unless loaded? {|person| !person.bad? }
  • There’s no good way to use CSV fixtures and has_and_belongs_to_many associations, in such a way that they are easily understandable and editable by non-technical people. Foxy fixtures solved a lot of issues with fixtures, but those advantages only work with YAML fixtures. Hence, if you have a HABTM situation, you’re stuck building a lot of rows of CSV referencing arbitrarily chosen IDs across several different files.

Post a Comment

Your Information (Name required. Email address will not be displayed with comment.)

* Copy This Password *

* Type Or Paste Password Here *