It's a long post, so I hope I haven't missed the point...
I'd say that having a single, well thought out database is better than having
two, so you are going in the right direction.
Yes, you can access related data from the Schedule model, so long as they are
associated (and even if they are not, actually). From within your Schedule
model you can do:
$this->Person->function();
...which will run 'function' in the Person model (find, read, save, a custom
function, whatever). Notice I didn't use $this->Schedule->Person->function() -
the Schedule model is not needed as you are already there. If you were running
this from the schedules controller, then you'd need to specify the Schedule
model.
You can also daisy chain the models; here's a completely made up example:
$this->Person->Area->Manager->Rosta->Timezone->Schedule->Shift->function();
The key is that you can walk through the belongsTo/hasMany/HABTM associations
as defined in your models. So in my fictitious example, Person belongsTo
Schedule, Area belongsTo Person, etc...
And don't forget the Containable behaviour that allows you to extract very
precise data queries.
You can also access a model that is not associated to the Schedule model by
using loadModel first:
$this->loadModel('Timezone');
$this-> Timezone->function();
Does that help?
Jeremy Burns
[email protected]
On 11 May 2010, at 00:14, paws_galuten wrote:
> Hi,
>
> My question is below, but first some info about the situation I'm in:
>
> I am taking an app that I wrote years ago for scheduling people in
> different areas of work at our Center, and re-writing it in cakePHP.
> In the mean time, I'm doing all sorts of things better than ever
> before ;)
>
> Among many other details, there are areas, people, shifts, etc. and
> the whole configuration (what people are scheduled for what shifts and
> at what time) is called a schedule. The person writing the schedule
> has a lot of work to do as people come in and out, and there was the
> necessity for a staging area. The way I did this in the old app, was
> to have two totally separate databases called scheduler_staging, and
> scheduler_public. This way, when the scheduler logged in, they would
> be editing the scheduler_staging database, and then when the schedule
> was ready, they could publish it, which would copy scheduler_staging
> to scheduler_public. I wanted to keep a record of all old publishes,
> so I added a table in scheduler_public called schedules and added a
> foreign key schedule_id to all other tables. So, when a schedule got
> published, it all of the data would be copied from scheduler_staging
> to scheduler_public, but with a new schedule_id.
>
> Ok, so that worked great, but now I'm learning that there are
> disadvantages to having multiple databases for one app. In my new
> cakePHP version of this app, I want to try to get all of this
> functionality under one "roof."
>
> One idea I had was to have scheduler_public be the only database (just
> call it scheduler) and in that schedules table have a boolean field
> called published. Or even better, a field called publish_date (which
> would be null if the schedule is not published yet). So the public
> could easily view the latest published schedule, and the scheduler who
> logs in could edit the schedule that has not been published yet.
>
> Two questions:
> 1. Am I going in the right direction here, or does this seem way
> off?
> 2. Assuming this works, could I just access everything through the
> schedule model? In other words, the current "schedule" is a group of
> data from all of the tables with the same schedule_id, so when I'm
> viewing schedule #2133 I would get everything I need as related model
> data from the schedule model... I am thinking the schedule id would be
> in the session which would default to the most recently published...
> so, the schedules controller would get the current schedule id from
> the session and hand it to the schedule model. If I want to view
> person #3, it would be ('controller' => 'schedules', 'action' =>
> 'view_person', 3) and then the schedule model would fetch the person
> data (and the shift data, and the area data... it's all needed to
> display a person and their info).
>
> I guess I'm back to question #1... does this make sense??
>
> Thanks so much for your thoughts,
> Jason
>
> Check out the new CakePHP Questions site http://cakeqs.org and help others
> with their CakePHP related questions.
>
> You received this message because you are subscribed to the Google Groups
> "CakePHP" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected] For more options, visit this group at
> http://groups.google.com/group/cake-php?hl=en
Check out the new CakePHP Questions site http://cakeqs.org and help others with
their CakePHP related questions.
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en