development with Rails, in which I'm currently developing the cart of the
I have a *line_items* model which *belongs_to :products*. This makes sense.
Later in the example we use this code to check if a product is referenced
by any line items before we destroy it:
class Product < ActiveRecord::Base
# ensure that there are no line items referencing this product
errors.add(:base, 'Line Items present')
This makes sense to me except of one part: if line_items.empty? I can only guess that *line_items *returns all the rows of the "line_items" table that contain the product.id of the currently instantiated Product object, is that right? But how does the model knows what to fetch just by "line_items"? Isn't that too little info that we give to our model, regarding the logic of the task it has to do? Don't we have to declare somewhere something like: *return false if line_items.product.id == product.id* ?
Thanks in advance people!
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/4LQoGwJO8J8J.
To post to this group, send email to firstname.lastname@example.org.
To unsubscribe from this group, send email to email@example.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.