<p>So I'm working on a Rails app to get the feeling for the whole thing. I've got a <code>Product</code> model that's a standard ActiveRecord model. However, I also want to get some additional product info from Amazon ECS. So my complete model gets some of its info from the database and some from the web service. My question is, should I:</p>

<ol>
<li><p>Make two models a Product and a ProductAWS, and then tie them together at the controller level.</p></li>
<li><p>Have the Product ActiveRecord model contain a ProductAWS object that does all the AWS stuff?</p></li>
<li><p>Just add all the AWS functionality to my Product model.</p></li>
<li><p>???</p></li>
</ol>

[{'answer_id': 70457, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>You can use the <code>composed_of</code> relationship in ActiveRecord. You make a regular class with all the attributes that you manage through AWS and specify that your Product-class is composed_of this class. ActiveRecord will handle the delegation of the mapped attributes to and from this class.</p>\n\n<p>See <a href="http://api.rubyonrails.org/classes/ActiveRecord/Aggregations/ClassMethods.html#M001265" rel="nofollow noreferrer">the documentation of composed_of</a></p>\n'}, {'answer_id': 70499, 'author': 'Hank Gay', 'author_id': 4203, 'author_profile': 'https://Stackoverflow.com/users/4203', 'pm_score': 0, 'selected': False, 'text': '<p>@Menno</p>\n\n<p>What about using <a href="http://wiki.rubyonrails.org/rails/pages/ActiveResource" rel="nofollow noreferrer">ActiveResource</a> for the AWS-attributes class?</p>\n'}, {'answer_id': 76143, 'author': 'Pete', 'author_id': 13472, 'author_profile': 'https://Stackoverflow.com/users/13472', 'pm_score': 2, 'selected': True, 'text': "<p>As with most things: it depends. Each of your ideas have merit. If it were me, I'd start out this way: </p>\n\n<pre><code>  class Product &lt; ActiveRecord::Base\n     has_one :aws_item\n  end \n  class AWSItem \n     belongs_to :product\n  end\n</code></pre>\n\n<p>The key questions you want to ask yourself are: </p>\n\n<p><strong>Are you only going to be offering AWS ECS items, or will you have other products?</strong> If you'll have products that have nothing to do with Amazon, don't care about ASIN, etc, then a has_one could be the way to go. Or, even better, a polymorphic relationship to a :vendable interface so you can later plug in different extension types. </p>\n\n<p><strong>Is it just behavior that is different, or is the data going to be largely different too?</strong> Because you might want to consider: </p>\n\n<blockquote>\n<pre><code>class Product &lt; ActiveRecord::Base\nend \nclass AWSItem &lt; Product\n  def do_amazon_stuff\n    ... \n  end\nend\n</code></pre>\n</blockquote>\n\n<p><strong>How do you want the system to perform when Amazon ECS isn't available?</strong> Should it throw exceptions? Or should you rely on a local cached version of the catalog?</p>\n\n<blockquote>\n<pre><code>class Product &lt; ActiveRecord::Base\n\nend\n\nclass ItemFetcher &lt; BackgrounDRb::Rails\n   def do_work\n      # .... Make a cached copy of your ECS catalog here. \n      # Copy the Amazon stuff into your local model\n   end\nend\n</code></pre>\n</blockquote>\n\n<p>Walk through these questions slowly and the answer will become clearer. If it doesn't, start prototyping it out. Good luck!</p>\n"}, {'answer_id': 77984, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>If you are retrieving data from two completely different sources (ActiveRecord on one hand and the Internet on the other), there are many benefits to keeping these as separate models. As the above poster wrote, Product has_one (or has_many) :aws_item.</p>\n'}]
['https://Stackoverflow.com/questions/70397', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/11284/']