Ben Johnson wrote:
product1.price
=> 20.00
product1.price = 100.00
=> 100.00
product1.category.product.price
=> 20.00
When visualizing the relationships between these 2 objects wouldn't it
make more sense for that last line of code to return 100.00?
Looks like you're just missing a save.
product1.price #=> 20.00
product1.price = 100.00 #=> 100.00
product1.save #=> true
product1.category.product.price #=> 100.00
If that does not work, the product could be cached in the category, so
try:
product1.category.product.reload.price
Dan Manges
Ben Johnson wrote:
The problem I'm having is that some models rely on values from other
models to be valid. If I change that value I want to make sure all of
the other model's objects are ok with it, but they all see the old
value, not the value in the object.
If you're going to have models rely on other models to be valid, I
would approach it a little differently. If changing the price of a
product can make a category invalid, in the product validation I would
check for this and then error with something like "price cannot be set
to this because categories depend on having a product with a certain
price" (or however your relationships are set up).
I've done this before in an application using workflows. If a certain
model is using a workflow, the workflow cannot be set to inactive. So
the one model validates that it has an active workflow, but then the
workflow model validates that it cannot be set to inactive if other
models are using it. Hopefully that makes sense.
Dan Manges