English 中文(简体)
Kohana ORM 不装货的模式
原标题:Kohana ORM Model not loading

在以下法典中,“附加”行动按预期起作用,但删除行动留下了一个错误,即Koha“Cannot去除偏爱物模式,因为它不是装满的”。

任何想法?

if ($_GET[ action ] ==  add )
{
    $favorites = ORM::factory( favorites );
    $favorites->question_id = $_GET[ question_id ];
    $favorites->user_id     = Kohana_Facebook::instance()->user_id();
    $favorites->save();
}
elseif ($_GET[ action ] ==  remove )
{
$favorites = ORM::factory( favorites )
    ->where( user_id ,  = , $facebook->user_id())
    ->and_where( question_id ,  = , $_GET[ question_id ])
    ->find();
$favorites->delete();
}

A var_dump($favorites) show this:

object(Model_Favorites)#24 (31) { 
["_table_name:protected"]=> string(9) "favorites" 
["_has_one:protected"]=> array(0) { } 
["_belongs_to:protected"]=> array(0) { } 
["_has_many:protected"]=> array(0) { } 
["_load_with:protected"]=> array(0) { } 
["_validation:protected"]=> NULL 
["_object:protected"]=> array(2) { ["user_id"]=> string(8) "60717257" ["question_id"]=> string(1) "2" } 
["_changed:protected"]=> array(0) { } 
["_related:protected"]=> array(0) { } 
["_valid:protected"]=> bool(false) 
["_loaded:protected"]=> bool(false) 
["_saved:protected"]=> bool(false) 
["_sorting:protected"]=> NULL 
["_foreign_key_suffix:protected"]=> string(3) "_id" 
["_object_name:protected"]=> string(9) "favorites" 
["_object_plural:protected"]=> string(11) "favoriteses" 
["_table_columns:protected"]=> array(2) { ["user_id"]=> array(13) { ["type"]=> string(3) "int" ["min"]=> string(11) "-2147483648" ["max"]=> string(10) "2147483647" ["column_name"]=> string(7) "user_id" 
["column_default"]=> NULL 
["data_type"]=> string(3) "int" 
["is_nullable"]=> bool(false) 
["ordinal_position"]=> int(1) 
["display"]=> string(2) "11" 
["comment"]=> string(0) "" 
["extra"]=> string(0) "" 
["key"]=> string(3) "PRI" 
["privileges"]=> string(31) "select,insert,update,references" } 
["question_id"]=> array(13) { ["type"]=> string(3) "int" ["min"]=> string(11) "-2147483648" ["max"]=> string(10) "2147483647" ["column_name"]=> string(11) "question_id" ["column_default"]=> NULL ["data_type"]=> string(3) "int" ["is_nullable"]=> bool(false) ["ordinal_position"]=> int(2) ["display"]=> string(2) "11" ["comment"]=> string(0) "" ["extra"]=> string(0) "" ["key"]=> string(3) "PRI" ["privileges"]=> string(31) "select,insert,update,references" } } ["_updated_column:protected"]=> NULL ["_created_column:protected"]=> NULL ["_primary_key:protected"]=> string(2) "id" ["_primary_key_value:protected"]=> NULL ["_table_names_plural:protected"]=> bool(true) ["_reload_on_wakeup:protected"]=> bool(true) ["_db:protected"]=> object(Database_MySQL)#23 (6) { ["_connection_id:protected"]=> string(40) "f9eb0f07846bef120d6d8414616f81f993f5306a" ["_identifier:protected"]=> string(1) "`" ["last_query"]=> string(98) "SELECT `favorites`.* FROM `favorites` WHERE `user_id` =  60717257  AND `question_id` =  2  LIMIT 1" ["_instance:protected"]=> string(7) "default" ["_connection:protected"]=> resource(73) of type (mysql link) ["_config:protected"]=> array(6) { ["type"]=> string(5) "mysql" ["connection"]=> array(3) { ["hostname"]=> string(9) "localhost" ["database"]=> string(17) "davekiss_dumbpoll" ["persistent"]=> bool(false) } ["table_prefix"]=> string(0) "" ["charset"]=> string(4) "utf8" ["caching"]=> bool(false) ["profiling"]=> bool(true) } } 
["_db_group:protected"]=> NULL 
["_db_applied:protected"]=> array(0) { } 
["_db_pending:protected"]=> array(0) { } 
["_db_reset:protected"]=> bool(true) 
["_db_builder:protected"]=> NULL 
["_with_applied:protected"]=> array(0) { } 
["_cast_data:protected"]=> array(0) { } }
最佳回答

Yes, it is not loaded in your code.

您需要在<条码>上添加<条码>。

www.un.org/Depts/DGACM/index_spanish.htm

我可以看到,它只是一个没有单一PK领域的关系表(id)。

您可以删除以下几句:

DB::delete( favorites )->where( user_id ,  = , $facebook->user_id())
                       ->and_where( question_id ,  = , $_GET[ question_id ])
                       ->execute(Database::instance());

或您可使用<代码>remove(>)方法(因为似乎与你一样利用kohana ORM的关系)。

问题回答

2. 同一问题,与解决办法保持一致

加入法典

受保护的美元——主轴 = 贵方的表格

I have the same issue after loading my codes with ->where() and ->find() Just make sure that the

<编码>受保护 (美元)

该模式界定。





相关问题
Kohana - subfolders within views folder

I m working on the admin section of a site using Kohana. I ve created a "admin" subfolder within the views folder to store admin views. I m also using a modified instance of the Template Controller ...

approach for "site down for maintenance"

I have been using Joomla and I love its administrative facility to put the site down for maintenance. As I have seen, all requests to the site if it is in maintenance mode is routed to a single page. ...

Kohana 3: using maintainable routes

I m using Kohana v3 for a web project, and today I found myself writing this: echo Html::anchor( user/view/ .$user->id, "See user s profile"); If I rename the action_view method in the User ...

Is using a Mail Model in MVC incorrect?

I have built a model in some of my MVC websites to assist with sending emails, generally I do something like this $mail = new Mail_Model; $mail->to( me@somewhere.com ); $mail->from( you@...

help on building a basic php search engine

i looked for tutorials everywhere but just can t seem to get a good one... a search page with pagination, column header sorting, and multiple filtering(filters are in checkboxes) the problem: had ...

What s the proper MVC way to do this....?

Quick question about general MVC design principle in PHP, using CodeIgniter or Kohana (I m actually using Kohana). I m new to MVC and don t want to get this wrong... so I m wondering if i have ...

Kohana Error... Attempt to assign property of non-object

So I m trying to go through the Version 3 Guide of Kohana and keep getting an error on the hello world create view part. ErrorException [ Warning ]: Attempt to assign property of non-object Line 8: $...

热门标签