gabordemooij / redbean

ORM layer that creates models, config and database on the fly
https://www.redbeanphp.com
2.31k stars 279 forks source link

Change id column value. #220

Closed diegocastro closed 11 years ago

diegocastro commented 11 years ago

I'm working on a project and I need to change the id column value.

Redbean currently does not change it to the value I specify.

Here is an exemple code:

$news_list = R::getCol('SELECT id FROM news');

$i = 1;

foreach ($news_list as $id) { $news = R::load('news', $id);

$news->id = $i;

R::store($news);

$i++;

}

gabordemooij commented 11 years ago

Unfortunately RedBeanPHP does not support this feature. You could use an R::exec('UPDATE ... ') to update the record manually though. Updating auto-increment columns seems tricky to me though.

diegocastro commented 11 years ago

Yeah, that's what I used.

I do not like to use it too. But this project have a specific need to do it. Thanks for the reply.

michaelmcmillan commented 11 years ago

Sorry for bugging you with this, but you should really make this clear in the documentation. I am now severely screwed.

gabordemooij commented 11 years ago

I'm sorry you have had some serious trouble with the schema restrictions. There is some much information to be conveyed using the website that it is often difficult to mention everything. I will try to highlight the limitations of RedBeanPHP more clearly.

BTW, not sure if this helps, you can always work with records and convert them to beans later: R::converToBeans($records) - this way you can use plain SQL.

michaelmcmillan commented 11 years ago

Hi Gabor,

I'm sorry for the harsh tone in my previous post. I understand that these restrictions is what makes RedBean so friendly. I solved the issue by using some pretty complex aliasing in my MySQL queries.

Thanks for the quick response, nevertheless!

On Sat, Nov 16, 2013 at 5:58 PM, Gabor de Mooij notifications@github.comwrote:

I'm sorry you have had some serious trouble with the schema restrictions. There is some much information to be conveyed using the website that it is often difficult to mention everything. I will try to highlight the limitations of RedBeanPHP more clearly.

BTW, not sure if this helps, you can always work with records and convert them to beans later: R::converToBeans($records) - this way you can use plain SQL.

— Reply to this email directly or view it on GitHubhttps://github.com/gabordemooij/redbean/issues/220#issuecomment-28630684 .