Why would a particular line: if @channel == nil && current_associate.watching_channel_id != nil && current_associate.watching_channel_id > 0 alsways output the statement: false to the console???? I am using Rails 2.3.2 -Janna B
I''m not sure, but you probably should rewrite that: if @channel.nil? && !current_associate.watching_channel_id.nil? && current_associate.watching_channel_id > 0 better still why are you checking if watching_channel_id is gt 0? Is watching_channel_id a foreign key for an association for watching channel? then you could do this: if @channel.nil? && current_associate.watching_channel Sorry I couldn''t specifically answer your question, but hope the code review was useful. Cheers, Nicholas On Jul 16, 7:47 pm, JannaB <mistressja...-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote:> Why would a particular line: > > if @channel == nil && current_associate.watching_channel_id != nil && > current_associate.watching_channel_id > 0 > > alsways output the statement: > > false > > to the console???? > > I am using Rails 2.3.2 -Janna B
yes, current_associate.watching_channel_id IS a foreign key to channel.id. But I have not specified it as such in the associate model or the channel model (not sure how -- or if I even need to!) -Janna On Jul 16, 8:56 pm, Nicholas Henry <nicholas.he...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''m not sure, but you probably should rewrite that: > > if @channel.nil? && !current_associate.watching_channel_id.nil? && > current_associate.watching_channel_id > 0 > > better still why are you checking if watching_channel_id is gt 0? Is > watching_channel_id a foreign key for an association for watching > channel? then you could do this: > > if @channel.nil? && current_associate.watching_channel > > Sorry I couldn''t specifically answer your question, but hope the code > review was useful. > > Cheers, > Nicholas > > On Jul 16, 7:47 pm, JannaB <mistressja...-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote: > > > Why would a particular line: > > > if @channel == nil && current_associate.watching_channel_id != nil && > > current_associate.watching_channel_id > 0 > > > alsways output the statement: > > > false > > > to the console???? > > > I am using Rails 2.3.2 -Janna B
Janna Brossard wrote:> yes, current_associate.watching_channel_id IS a foreign key to > channel.id. But I have not specified it as such in the associate model > or the channel model (not sure how -- or if I even need to!) -Jannaif the class name is WatchingChannel, the it will work belongs_to :watching_channel if the class name of the watching channel is something else, like Channel, then it will work belongs_to :watching_channel, :class_name => "Channel", :foreign_key => "watching_channel_id" it''s always false because either @channel is not null, the foreign key is not null or the foreign key is zero. Note that you should never have a foreign key with a zero value If you make the modification in your model, you can easily do if @channel.nil? and current_associate.watching_channel and finally @channel.nil? and @channel == nil is almost the same thing, @channel.nil? is easier to read, dough -- Posted via http://www.ruby-forum.com/.
so to use your statement, I should put the following in my Associate model? belongs_to :watching_channel, :class_name => "Channel", :foreign_key => "watching_channel_id" -Janna B On Jul 17, 1:09 am, Rodrigo Dominguez <rails-mailing-l...@andreas- s.net> wrote:> Janna Brossard wrote: > > yes, current_associate.watching_channel_id IS a foreign key to > > channel.id. But I have not specified it as such in the associate model > > or the channel model (not sure how -- or if I even need to!) -Janna > > if the class name is WatchingChannel, the it will work > > belongs_to :watching_channel > > if the class name of the watching channel is something else, like > Channel, then it will work > > belongs_to :watching_channel, :class_name => "Channel", :foreign_key => > "watching_channel_id" > > it''s always false because either @channel is not null, the foreign key > is not null or the foreign key is zero. > > Note that you should never have a foreign key with a zero value > > If you make the modification in your model, you can easily do > > if -Z6lK/4IYDTmxo9EaB6oYFg@public.gmane.org? and current_associate.watching_channel > > and finally > > @channel.nil? and @channel == nil is almost the same thing, > @channel.nil? is easier to read, dough > -- > Posted viahttp://www.ruby-forum.com/.
That should work. Cheers, Nicholas On Jul 17, 8:47 am, JannaB <mistressja...-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote:> so to use your statement, I should put the following in my Associate > model? > > belongs_to :watching_channel, :class_name => "Channel", :foreign_key > => > "watching_channel_id" > > -Janna B > > On Jul 17, 1:09 am, Rodrigo Dominguez <rails-mailing-l...@andreas- > > > > s.net> wrote: > > Janna Brossard wrote: > > > yes, current_associate.watching_channel_id IS a foreign key to > > > channel.id. But I have not specified it as such in the associate model > > > or the channel model (not sure how -- or if I even need to!) -Janna > > > if the class name is WatchingChannel, the it will work > > > belongs_to :watching_channel > > > if the class name of the watching channel is something else, like > > Channel, then it will work > > > belongs_to :watching_channel, :class_name => "Channel", :foreign_key => > > "watching_channel_id" > > > it''s always false because either @channel is not null, the foreign key > > is not null or the foreign key is zero. > > > Note that you should never have a foreign key with a zero value > > > If you make the modification in your model, you can easily do > > > if -Z6lK/4IYDTmxo9EaB6oYFg@public.gmane.org? and current_associate.watching_channel > > > and finally > > > @channel.nil? and @channel == nil is almost the same thing, > > @channel.nil? is easier to read, dough > > -- > > Posted viahttp://www.ruby-forum.com/.