set_primary_keyã§ã¯ã¾ã£ããã¨ãããRailsã¬ã·ãã®ãã»ã¼ãsetç³»ã¡ã½ããã§ãã£ã¡ãã£ã話
æã®ã¢ããªã®DBã«ActiveRecordã§ç¹ããå¿
è¦ãã§ãã®ã§
ãã©ã¤ããªãã¼ã®ååãå¤æ´ããset_primary_keyã¨ããã¡ã½ããã使ãã¾ããã
ããããåããªãããidã¯ãªãåã§ãã¨ã§ãã
ãªãã§ã ããã
Railsã¬ã·ãã®éãã«æ¸ãã¦ãã®ã«ã
ï¼ééãçï¼
set_primary_key = :hoge_id
éããããã®ååããã§ãã¯ã
ãããããsetãªãã ãã=ãããªããªãï¼
ãã¼ãããããã°ã
ï¼æ£ããçï¼
set_primary_key :hoge_id
ã¨æ¸ãã¦ã¿ãã¨ãã
åããã¼ã¼ã¼ã¼ï¼ï¼ï¼
railsã¬ã·ãã®ãã»ã¼ã¼ã
ããããªãã§ã¨ã©ã¼ã§ãªããã ï¼
ã¨ãã½ã¼ã¹ãè¦ãããããããã¨ã ã£ãã
set_primary_keyã®å®ç¾© def set_primary_key(value = nil, &block)
å¼æ°ãªãã§ãåããããã
ã£ã¦ãã¨ã¯
set_primary_keyãå¼æ°ãªãã§å®è¡ããããã®æ»ãå¤ã«=ã§ä»£å
¥ããã¨ãã
æå³ã®ãªããã¨ããã¦ããã®ããã
ããã¯ä»å以å¤ã®å ´åã§ãæ°ã¥ããã«ãã£ã¡ããããã ãã
ããã以å¤ã«ç ç²è
ãã§ãªããã¨ãç¥ãã¾ãã