Forum: Ruby on Rails remove element from array question

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ukrit H. (Guest)
on 2009-01-26 10:50
suppose that I've some kind of array like this

var1[0].var2[0].var3

So I would like to remove var3 out of this nest array
what I should do?

and after I tried to use delete It's also delete some important value
out from database any idea?!
Ukrit H. (Guest)
on 2009-01-26 11:19
Ukrit H. wrote:
> suppose that I've some kind of array like this
>
> var1[0].var2[0].var3
>
> So I would like to remove var3 out of this nest array
> what I should do?
>
> and after I tried to use delete It's also delete some important value
> out from database any idea?!

hello???????????
Martin H. (Guest)
on 2009-01-26 12:16
(Received via mailing list)
a=["a","b","c"]
a.pop="c"
a is now ["a","b"]

Is that what you want?
Martin

On Jan 26, 9:19 am, Ukrit H. <removed_email_address@domain.invalid>
Maurício L. (Guest)
on 2009-01-26 14:22
(Received via mailing list)
Would you like to remove the object that contains var3?

var3 isn' at the nested array, it's a nested property of an object
that is in there.

If you wanted to remove it, it would be like this:

var1[0].var2.delete_at( 0 )

-
Maurício Linhares
http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/
(en)



On Mon, Jan 26, 2009 at 5:50 AM, Ukrit H.
Ukrit H. (Guest)
on 2009-01-27 03:46
Maurício Linhares wrote:
> Would you like to remove the object that contains var3?
>
> var3 isn' at the nested array, it's a nested property of an object
> that is in there.
>
> If you wanted to remove it, it would be like this:
>
> var1[0].var2.delete_at( 0 )
>
> -
> Maurí£©o Linhares
> http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/
> (en)
>
>
>
> On Mon, Jan 26, 2009 at 5:50 AM, Ukrit H.

not really what I want is removing element inside an array built from
query (use in display purpose). but when I'm trying to delete the
element inside database also deleted.

for more clearer explanation please see this:

I've got database contains stuff like this:

var1 - has_many var2

var2 - belongs to var1 and belongs to var2

var3 - has_many var2

So what I'm doing is

variable1 = var1.find(:all)

but I need only var1 which not contains some contents in var3 that's why
I need to trace and remove from var3 element. any Idea?
Andrius C. (Guest)
on 2009-01-27 13:40
(Received via mailing list)
var1.all(:select => 'var1.*', :include => {:var2 => var3}, :conditions
=> ['var3.something = ?', some_value])
This topic is locked and can not be replied to.