Article View: pl.comp.lang.ruby
Article #827Re: RoR vs PHP
From: Jaroslaw Zabiello
Date: Wed, 02 Jan 2008 03:53
Date: Wed, 02 Jan 2008 03:53
37 lines
2203 bytes
2203 bytes
On Tue, 01 Jan 2008 23:14:53 -0000, Jaroslaw Zabiello <abuse@tpnet.pl>
wrote:
> class Child1 < Sequel::Model(:childs1)
> set_schema do
> primary_key :parent_id
> varchar :pole1
> end
> class << self
> def next_id
> self.select(:max[:parent_id].as(:last_id)).first.last_id.to_i + 1
> end
> end
> before_save do
> unless Parent.filter(:id => Child1.next_id).first
> raise 'Parent cannot assign more childs1 objects'
> end
> end
> end
To samo, ale krócej:
class Child1 < Sequel::Model(:childs1)
set_schema do
primary_key :parent_id
varchar :pole1
end
before_save do
unless Parent[Child1.max(:parent_id).to_i + 1]
raise 'Parent cannot assign more childs1 objects'
end
end
end
--
Jarosław Zabiełło
http://blog.zabiello.com
Technical Details
Message-ID:
<op.t4aafpggr2rg33@jzmbp.local>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!not-for-mailReferences:
<fl6ahk$m1q$1@inews.gazeta.pl> <op.t351icnsr2rg33@jzmbp.local> <fl93bh$d8p$1@inews.gazeta.pl> <r4il45-1ar.ln1@router.piechotka.com.pl> <op.t358bkfwr2rg33@jzmbp.local> <fl9aau$9b9$5@inews.gazeta.pl> <20071231084648.6d47feda.gryf_esm-no@spam-o2.pl> <op.t37dq3ydr2rg33@jzmbp.local> <0enn45-u25.ln1@router.piechotka.com.pl> <op.t37qnpdrr2rg33@jzmbp.local> <3pbo45-ha7.ln1@router.piechotka.com.pl> <op.t3777x1jr2rg33@jzmbp.local> <jtip45-n8c.ln1@router.piechotka.com.pl> <op.t388lvhur2rg33@jzmbp.local> <h96q45-37f.ln1@router.piechotka.com.pl> <op.t39jhmarr2rg33@jzmbp.local> <grhq45-5dg.ln1@router.piechotka.com.pl> <op.t39xi4kdr2rg33@jzmbp.local>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!not-for-mail From: "Jaroslaw Zabiello" <abuse@tpnet.pl> Newsgroups: pl.comp.lang.ruby Subject: Re: RoR vs PHP Date: Wed, 02 Jan 2008 03:53:39 -0000 Organization: "Portal Gazeta.pl -> http://www.gazeta.pl" Lines: 37 Message-ID: <op.t4aafpggr2rg33@jzmbp.local> References: <fl6ahk$m1q$1@inews.gazeta.pl> <op.t351icnsr2rg33@jzmbp.local> <fl93bh$d8p$1@inews.gazeta.pl> <r4il45-1ar.ln1@router.piechotka.com.pl> <op.t358bkfwr2rg33@jzmbp.local> <fl9aau$9b9$5@inews.gazeta.pl> <20071231084648.6d47feda.gryf_esm-no@spam-o2.pl> <op.t37dq3ydr2rg33@jzmbp.local> <0enn45-u25.ln1@router.piechotka.com.pl> <op.t37qnpdrr2rg33@jzmbp.local> <3pbo45-ha7.ln1@router.piechotka.com.pl> <op.t3777x1jr2rg33@jzmbp.local> <jtip45-n8c.ln1@router.piechotka.com.pl> <op.t388lvhur2rg33@jzmbp.local> <h96q45-37f.ln1@router.piechotka.com.pl> <op.t39jhmarr2rg33@jzmbp.local> <grhq45-5dg.ln1@router.piechotka.com.pl> <op.t39xi4kdr2rg33@jzmbp.local> NNTP-Posting-Host: 89.124.240.242 Mime-Version: 1.0 X-Trace: inews.gazeta.pl 1199246021 20674 89.124.240.242 (2 Jan 2008 03:53:41 GMT) X-Complaints-To: usenet@agora.pl NNTP-Posting-Date: Wed, 2 Jan 2008 03:53:41 +0000 (UTC) X-User: hipertracker User-Agent: Opera Mail/9.25 (MacIntel) Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit