Display Join Records Data in order of they created in Postgresql and Ruby On Rails -



Display Join Records Data in order of they created in Postgresql and Ruby On Rails -

i have 3 tables in postgresql database:

members

id first_name last_name created_at

payments (like debit)

id member_id amount created_at type

fees (like credit)

id member_id amount created_at type

i show them in single view billing statements: , used next queries:

select * members t1 left bring together payments t2 on (t1.id=t2.member_id) left bring together fees t3 on (t1.id=t3.member_id)

and shows me next results:

id | amount | created_at | type 1 100 25-12-2013 fee 2 100 29-12-2013 fee 3 100 25-12-2013 payment 4 100 23-12-2013 payment

but issue shows first fees record , payments while need should order created_at , should below:

id | amount | created_at | type 1 100 23-12-2013 payment 2 100 25-12-2013 fee 3 100 25-12-2013 payment 4 100 29-12-2013 fee

here details of models:

class fee < activerecord::base # setup accessible (or protected) attributes model attr_accessible :member_id,:fee_type,:amount,:reason,:details,:date # setup relations relative models belongs_to :member # validates rule here validates_numericality_of :member_id,:fee_type,:amount validates :reason, :format => {:with => /^[-a-za-z0-9_ ]+$/ }, :length => {:maximum => 255}, :presence =>true validates :details, :format => {:with => /^[-a-za-z0-9_ ]+$/ }, :length => {:maximum => 255}, :allow_blank =>true validates :amount, :presence => true validates :member_id, :presence => true validates :date, :presence => true # search start here self.per_page = 10 end class payment < activerecord::base # setup accessible (or protected) attributes model attr_accessible :member_id,:payment_category_id,:payment_type_id,:payment_date,:amount,:notes,:is_send_email,:last_sent,:date_deposite # setup relations relative models belongs_to :payment_type belongs_to :payment_category belongs_to :member # validates rule here validates_numericality_of :member_id,:payment_category_id,:payment_type_id,:amount validates :notes, :format => {:with => /^[-a-za-z0-9_ ]+$/ }, :length => {:maximum => 255}, :allow_blank =>true validates :amount, :presence => true, :length => {:maximum => 15} validates :member_id, :presence => true validates :payment_date, :presence => true # pagiination start here self.per_page = 10 end class fellow member < activerecord::base has_many :payment, dependent: :destroy, -> { order :created_at } has_many :fee, dependent: :destroy, -> { order :created_at } has_many :events, :through => :participants end

depending on how many records pulling out, can sorting in ruby after pulling them out of database eg

transactions = member.payments + member.fees transactions = transactions.flatten.sort_by(&:created_at)

ruby-on-rails postgresql postgresql-9.1

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -