Hi,

This is my recent project where is started to use STI for extend my Ad
model. I never before used STI and many people which i recently discuss
not recommended me to use this method.

1. What are the advantages and disadvanteges of STI and why i should use
delegation ??

2. And how in delegation i can separate validation like below?

Ride coordination board: Singe Table Inheritance
Database: ads
:title
:price
:content
:username
:from
:to
Model: regular AD
:title
:price
:ad_content
:username
Model: Ride AD
:title
:price
:username
---
:from
:to


STI:
class Ad < ActiveRecord::Base
validates_presence_of :name, :email, :price
validates_presence_of :title, :ad_content, if: is_regular?
validates_presence_of :from, :to, unless: is_regular?

def is_regular?
self.type.nil?
end
end

class RideAd < Ad
end

--
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedFeb 13, '12 at 2:20p
activeFeb 13, '12 at 2:20p
posts1
users1
websiterubyonrails.org
irc#RubyOnRails

1 user in discussion

Darek F.: 1 post

People

Translate

site design / logo © 2021 Grokbase