如何检查它是否返回null?

时间:2022-04-04 07:18:51

i should check whether there is some values based on this condition. if there is some, then i should do one action or else do a different action. i work on rails, mysql and xp
this is not working @test.nil?
suggest me a alternate way
@test=Model.find(:all,:conditions=>"id=@someid")
thanks in advance

我应该根据这个条件检查是否有一些值。如果有一些,那么我应该做一个动作,否则做一个不同的行动。我在rails,mysql和xp上工作这不起作用@ test.nil?建议我另一种方式@test = Model.find(:all,:conditions =>“id = @ someid”)提前感谢

1 个解决方案

#1


@test.nil? should work fine. It's probably not working because your find method is wrong. Try this instead:

@ test.nil?应该工作正常。它可能不起作用,因为你的find方法是错误的。试试这个:

@test = Model.find_by_id(@someid)

An alternative syntax is:

另一种语法是:

@test = Mode.find(@someid)

—Which will raise a RecordNotFound exception if the record doesn't exist.

- 如果记录不存在,它将引发RecordNotFound异常。

#1


@test.nil? should work fine. It's probably not working because your find method is wrong. Try this instead:

@ test.nil?应该工作正常。它可能不起作用,因为你的find方法是错误的。试试这个:

@test = Model.find_by_id(@someid)

An alternative syntax is:

另一种语法是:

@test = Mode.find(@someid)

—Which will raise a RecordNotFound exception if the record doesn't exist.

- 如果记录不存在,它将引发RecordNotFound异常。