I guess you're right - maybe I should give it another go using 
validate_on_create and before_create

Jeff Cohen wrote:
> Why not?  Sounds like an InventoryItem is associated to a Character,
> and so you should have access to all of Character's related tables as
> well.  Maybe I'm missing something about the way you've setup your
> models?

Well, it's like this:
- Character has many InventoryItems
- InventoryItems belongs to Item (an "item type" you could say)
- Recipe belongs to Item

So when a new InventoryItem is created it has no "direct association" to 
a certain recipe - because recipe belongs to one Item (not 
InventoryItem). More than one recipe can belongs to the same Item.

This is why it is hard to do the validations inside InventoryItem. 
However, enlightened by your reply, I've made the following solution:

[code]
class InventoryItem < ActiveRecord::Base
  belongs_to :item
  belongs_to :character
  attr_accessor :recipe

  def recipe=(recipe)
    self.item_id = recipe.product_item_id
  end

  def self.new_from_recipe(recipe)
    new :recipe => recipe
  end

  def after_create
    # something
  end

  def validate_on_create
    # something
  end
end
[/code]

Do you see a better/simpler solution?
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to