S
serbulentunsal
Hi all,
I'm using Windows Xp, Mysql 5, Webrick, Rails 1.0 I've 3 tables which
have HABTM relationship. My tables names are all set to uncountble.
Name
of tabels are anabilimdali (includes department info id name etc.),
ogretimuye (personel information like id , name , dept. ) yayin
(document information), and for relationships yayin_anabilimdali ,
yayin_ogretimuye .
The relationship between yayin_anabilimdali is ok. But i can't write
any
parameters to yayin_ogretimuye table when I try to create new yayin
object. The object was successfully creted in yayin table and the
relationship was successfully created in yayin_anabilimdali table.
Here
is the codes;
model
yayin.rb
class Yayin < ActiveRecord::Base
has_and_belongs_to_many gretimuye
has_and_belongs_to_many :anabilimdali
end
controller
yayin_controller.rb
class YayinController < ApplicationController
model :yayin
.....
.....
def new
@anabilimdali = Anabilimdali.find all , rder => "ad")
@ogretimuye = Ogretimuye.find all , rder => "ad")
end
def create
@anabilimdali = Anabilimdali.find_all
@ogretimuye = Ogretimuye.find_all
item = Yayin.new
item.attributes = @params["yayin"]
if item.save
for anabilimdali in @anabilimdali
if (@params[anabilimdali.ad])
item.anabilimdali<<(anabilimdali)
end
end
for ogretimuye in @ogretimuye
if (@params[ogretimuye[ogretimuye.id] == ogretimuye.id )
item.ogretimuye<<(ogretimuye)
end
end
redirect_toaction => "list")
else
render_text "Couldn't add new item"
end
end
....
....
View
new.rhtml
<h1>New yayin</h1>
<%= start_form_tag :action => 'create' %>
<%= render artial => 'form' %>
<p><label for="yayin_anabilimdali">Anabilimdalllari</label><br />
<% for @anabilimdali in @anabilimdali %>
<%= @anabilimdali.ad %> : <input type="checkbox" name="<%=
@anabilimdali.ad %>" value="0"/><br />
<% end %>
</p>
<p><label for="yayin_ogretimuye">Yazarlar</label><br />
<%for ogretimuye in @ogretimuye%>
<select name=ogretimuye[ogretimuye.id][] multiple>
<option value="<%=ogretimuye.id%>"> <%=ogretimuye.ad%>
<%=ogretimuye.soyad%> </option>
<%end%>
</p>
</select>
<%= submit_tag "Create" %>
<%= end_form_tag %>
<%= link_to 'Back', :action => 'list' %>
And the development.log
Processing YayinController#create (for 127.0.0.1 at 2005-12-17
12:52:05)
[POST]
Parameters: {"commit"=>"Create",
"ogretimuye"=>{"ogretimuye.id"=>["161"]}, "yayin"=>{"ad"=>"888888888"},
"action"=>"create", "controller"=>"yayin", "AAT\375p"=>"0"}
[4;36;1mAnabilimdali Load (0.000000)[0m [0;1mSELECT * FROM
anabilimdali [0m
[4;35;1mOgretimuye Load (0.079000)[0m [0mSELECT * FROM
ogretimuye
[0m
[4;36;1mYayin Columns (0.015000)[0m [0;1mSHOW FIELDS FROM
yayin[0m
[4;35;1mSQL (0.000000)[0m [0mBEGIN[0m
[4;36;1mSQL (0.000000)[0m [0;1mINSERT INTO yayin (`kabul_yil`,
`yayin_yil`, `ad`, `cilt`, `index_tur`, `ozet`, `issn`, `sayfalar`,
`yayinlayici`, `tur`, `yer`, `yer_tur`, `dil`, `index`, `sayi`,
`anahtar`, `yerli_yabanci`) VALUES(0, NULL, '888888888', NULL, NULL,
'',
NULL, NULL, '', '0', NULL, '0', '', NULL, NULL, '', '')[0m
[4;35;1mSQL (0.047000)[0m [0mCOMMIT[0m
[4;36;1mAnabilimdali Columns (0.000000)[0m [0;1mSHOW FIELDS FROM
anabilimdali[0m
[4;35;1mAnabilimdali Load (0.000000)[0m [0mSELECT * FROM
anabilimdali LEFT JOIN anabilimdali_yayin ON anabilimdali.id =
anabilimdali_yayin.anabilimdali_id WHERE (anabilimdali_yayin.yayin_id =
20 ) [0m
[4;36;1mSQL (0.000000)[0m [0;1mBEGIN[0m
[4;35;1manabilimdali_yayin Columns (0.015000)[0m [0mSHOW FIELDS
FROM anabilimdali_yayin[0m
[4;36;1mSQL (0.000000)[0m [0;1mINSERT INTO anabilimdali_yayin
(`anabilimdali_id`, `yayin_id`) VALUES (41, 20)[0m
[4;35;1mSQL (0.047000)[0m [0mCOMMIT[0m
[4;36;1mOgretimuye Columns (0.016000)[0m [0;1mSHOW FIELDS FROM
ogretimuye[0m
I'm using Windows Xp, Mysql 5, Webrick, Rails 1.0 I've 3 tables which
have HABTM relationship. My tables names are all set to uncountble.
Name
of tabels are anabilimdali (includes department info id name etc.),
ogretimuye (personel information like id , name , dept. ) yayin
(document information), and for relationships yayin_anabilimdali ,
yayin_ogretimuye .
The relationship between yayin_anabilimdali is ok. But i can't write
any
parameters to yayin_ogretimuye table when I try to create new yayin
object. The object was successfully creted in yayin table and the
relationship was successfully created in yayin_anabilimdali table.
Here
is the codes;
model
yayin.rb
class Yayin < ActiveRecord::Base
has_and_belongs_to_many gretimuye
has_and_belongs_to_many :anabilimdali
end
controller
yayin_controller.rb
class YayinController < ApplicationController
model :yayin
.....
.....
def new
@anabilimdali = Anabilimdali.find all , rder => "ad")
@ogretimuye = Ogretimuye.find all , rder => "ad")
end
def create
@anabilimdali = Anabilimdali.find_all
@ogretimuye = Ogretimuye.find_all
item = Yayin.new
item.attributes = @params["yayin"]
if item.save
for anabilimdali in @anabilimdali
if (@params[anabilimdali.ad])
item.anabilimdali<<(anabilimdali)
end
end
for ogretimuye in @ogretimuye
if (@params[ogretimuye[ogretimuye.id] == ogretimuye.id )
item.ogretimuye<<(ogretimuye)
end
end
redirect_toaction => "list")
else
render_text "Couldn't add new item"
end
end
....
....
View
new.rhtml
<h1>New yayin</h1>
<%= start_form_tag :action => 'create' %>
<%= render artial => 'form' %>
<p><label for="yayin_anabilimdali">Anabilimdalllari</label><br />
<% for @anabilimdali in @anabilimdali %>
<%= @anabilimdali.ad %> : <input type="checkbox" name="<%=
@anabilimdali.ad %>" value="0"/><br />
<% end %>
</p>
<p><label for="yayin_ogretimuye">Yazarlar</label><br />
<%for ogretimuye in @ogretimuye%>
<select name=ogretimuye[ogretimuye.id][] multiple>
<option value="<%=ogretimuye.id%>"> <%=ogretimuye.ad%>
<%=ogretimuye.soyad%> </option>
<%end%>
</p>
</select>
<%= submit_tag "Create" %>
<%= end_form_tag %>
<%= link_to 'Back', :action => 'list' %>
And the development.log
Processing YayinController#create (for 127.0.0.1 at 2005-12-17
12:52:05)
[POST]
Parameters: {"commit"=>"Create",
"ogretimuye"=>{"ogretimuye.id"=>["161"]}, "yayin"=>{"ad"=>"888888888"},
"action"=>"create", "controller"=>"yayin", "AAT\375p"=>"0"}
[4;36;1mAnabilimdali Load (0.000000)[0m [0;1mSELECT * FROM
anabilimdali [0m
[4;35;1mOgretimuye Load (0.079000)[0m [0mSELECT * FROM
ogretimuye
[0m
[4;36;1mYayin Columns (0.015000)[0m [0;1mSHOW FIELDS FROM
yayin[0m
[4;35;1mSQL (0.000000)[0m [0mBEGIN[0m
[4;36;1mSQL (0.000000)[0m [0;1mINSERT INTO yayin (`kabul_yil`,
`yayin_yil`, `ad`, `cilt`, `index_tur`, `ozet`, `issn`, `sayfalar`,
`yayinlayici`, `tur`, `yer`, `yer_tur`, `dil`, `index`, `sayi`,
`anahtar`, `yerli_yabanci`) VALUES(0, NULL, '888888888', NULL, NULL,
'',
NULL, NULL, '', '0', NULL, '0', '', NULL, NULL, '', '')[0m
[4;35;1mSQL (0.047000)[0m [0mCOMMIT[0m
[4;36;1mAnabilimdali Columns (0.000000)[0m [0;1mSHOW FIELDS FROM
anabilimdali[0m
[4;35;1mAnabilimdali Load (0.000000)[0m [0mSELECT * FROM
anabilimdali LEFT JOIN anabilimdali_yayin ON anabilimdali.id =
anabilimdali_yayin.anabilimdali_id WHERE (anabilimdali_yayin.yayin_id =
20 ) [0m
[4;36;1mSQL (0.000000)[0m [0;1mBEGIN[0m
[4;35;1manabilimdali_yayin Columns (0.015000)[0m [0mSHOW FIELDS
FROM anabilimdali_yayin[0m
[4;36;1mSQL (0.000000)[0m [0;1mINSERT INTO anabilimdali_yayin
(`anabilimdali_id`, `yayin_id`) VALUES (41, 20)[0m
[4;35;1mSQL (0.047000)[0m [0mCOMMIT[0m
[4;36;1mOgretimuye Columns (0.016000)[0m [0;1mSHOW FIELDS FROM
ogretimuye[0m