Friday, January 28, 2011

Re: Cake 2 : Any sort of automatic schema creation from models?

I was responding to the the post from Ryan about 'bake' doing what I
was asking for. When I 'run' a project in grails, that is when the
table construction from a model is done, so i thought there was more
to 'bake' than I had originally thought.

I did go through the blog tutorial as well as the docs on how to
create a model. And from what I remember, in both places I had to
create the db table myself.

You give the docs too much credit to think that in 15 minutes I am
supposed to understand why I have to create the db table: 'posts' by
hand (http://book.cakephp.org/view/1530/Creating-the-Blog-Database)
and then little bit later have to create a model 'Post' with only a
property of 'name' that = 'Post' with no other methods. And even then,
the reason for that '$name' property isnt exactly clear as to why it's
needed: 'The $name variable is always a good idea to add, and is used
to overcome some class name oddness in PHP4.'

I can understand the logic that the model is an interface to that
table, but I dont remember seeing that outlined anywhere.

So back to my original questions and just to be clear....
what you are saying is that the only way a table and it's rows are
created are by manually creating them in the db myself, right?


On Jan 28, 2:44 pm, AD7six <andydawso...@gmail.com> wrote:
> On Jan 28, 5:04 pm, maxarbos <maxar...@yahoo.com> wrote:
>
> > I read through the very minimal bake command documentation at: 9.1 and
> > 9.2 in the docs, but it's pretty superficial.
> > The generation of the schema is a pretty big deal i think and
> > something that should be highlighted a little more, if this is what it
> > can do.
>
> > When I started with cake 1.3 a few months ago,
>
> bake has very little to do with your question
>
> In cake you edit your db tables however you want and create a model
> file to represent your php interface to that table. Creating model
> files is actually optional since cake will use an app model instance
> for any referenced model which doesn't have a specific file. Therefore
> if you add a table to your db foos and add this to your e.g. user
> model:
>
> var hasMany = array('Foo');
>
> you can immediately do $this->Foo->find() in/from your user model.
>
> The blog tutorial should have cemented this for you in the first 15
> minute of using cake - if that wasn't the case for you I'd suggest you
> edit the bit that didn't clarify that's how cake works.
>
> AD

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: