Re: Database / Relationship question (habtm)

2009-07-21 Thread ulterior

That actually makes perfect sense. I guess I was trying to overthink
the whole thing. Thanks very much!

-Chris

On Jul 21, 12:27 pm, George  wrote:
> You really need to think of the three entities separately first, and
> decide how they should be related before you go on and start coding.
> Making an ER diagram is usually very helpful. (look it up if you don't
> know what an ER diagram is...you'll find a ton of info).
>
> It sounds like your app is like a bulletin board. In that case, off
> the top of my head, how I'd first flesh it out follows:
> Categories can have many topics
> Topics belong to a category
> Profiles can have many topics (a user can start many topics)
> Topics belong to many profiles (topics are written to by more than one
> user)
> Categories and Profiles don't need a relationship; their relation can
> be inferred by the other relationships if need be. I guess if you
> REALLY wanted to know who created a category though, you'd have
> Categories belong to Profiles and Profiles Have Many Categories, but I
> won't include that.
>
> So you'd have:
> Categories Have Many Topics
> Topics Belong To Categories
> Profiles HABTM Topics
>
> And you'd need the tables:
> categories, topics, profiles, profiles_topics
>
> Now, if this was a BB, you'd also have posts. And Posts would belong
> to Topics (threads) and Topics would have many Posts.
>
> That's how I'd do it I guess. If your app is different from that
> though, then your relationships would possibly be different and you'd
> have to follow the previous post's advice and ask yourself those
> questions. I think an ER diagram will help you a lot to figure out
> what you want before you spend a lot of time coding in the wrong
> direction.
>
> On Jul 21, 10:06 am, ulterior  wrote:
>
> > I'm somewhat new to cake, this is my second app and I'm having
> > problems with relationships. The first app I created was pretty
> > straightforward and I had a great time writing it in cake but my
> > database skills aren't up to par with my php! Here goes:
>
> > I have three tables that contain data which I want to relate,
> > profiles, categories and topics. I created a categories_topics table
> > with category_id and topic_id and that's just fine.
>
> > However, I want to link the categories and topics to profiles so I
> > created categories_topics_profiles which contains the
> > category_topic_id (from the join table) and the profile_id (to link to
> > the Profiles model) but it's giving me errors when I try to run a
> > simple find.
>
> > Is this the right way to build the tables or am I missing something?
> > Any help would be GREATLY appreciated.
>
> > Thanks,
> > -Chris
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Database / Relationship question (habtm)

2009-07-21 Thread George

You really need to think of the three entities separately first, and
decide how they should be related before you go on and start coding.
Making an ER diagram is usually very helpful. (look it up if you don't
know what an ER diagram is...you'll find a ton of info).

It sounds like your app is like a bulletin board. In that case, off
the top of my head, how I'd first flesh it out follows:
Categories can have many topics
Topics belong to a category
Profiles can have many topics (a user can start many topics)
Topics belong to many profiles (topics are written to by more than one
user)
Categories and Profiles don't need a relationship; their relation can
be inferred by the other relationships if need be. I guess if you
REALLY wanted to know who created a category though, you'd have
Categories belong to Profiles and Profiles Have Many Categories, but I
won't include that.

So you'd have:
Categories Have Many Topics
Topics Belong To Categories
Profiles HABTM Topics

And you'd need the tables:
categories, topics, profiles, profiles_topics

Now, if this was a BB, you'd also have posts. And Posts would belong
to Topics (threads) and Topics would have many Posts.

That's how I'd do it I guess. If your app is different from that
though, then your relationships would possibly be different and you'd
have to follow the previous post's advice and ask yourself those
questions. I think an ER diagram will help you a lot to figure out
what you want before you spend a lot of time coding in the wrong
direction.

On Jul 21, 10:06 am, ulterior  wrote:
> I'm somewhat new to cake, this is my second app and I'm having
> problems with relationships. The first app I created was pretty
> straightforward and I had a great time writing it in cake but my
> database skills aren't up to par with my php! Here goes:
>
> I have three tables that contain data which I want to relate,
> profiles, categories and topics. I created a categories_topics table
> with category_id and topic_id and that's just fine.
>
> However, I want to link the categories and topics to profiles so I
> created categories_topics_profiles which contains the
> category_topic_id (from the join table) and the profile_id (to link to
> the Profiles model) but it's giving me errors when I try to run a
> simple find.
>
> Is this the right way to build the tables or am I missing something?
> Any help would be GREATLY appreciated.
>
> Thanks,
> -Chris
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Database / Relationship question (habtm)

2009-07-21 Thread brian

How are these 3 models related? Can a Topic belong to more than one Category?

And how is Profile related to either of the others? A Topic has a
Profile? One or more? What about Category?

On Tue, Jul 21, 2009 at 11:06 AM, ulterior wrote:
>
> I'm somewhat new to cake, this is my second app and I'm having
> problems with relationships. The first app I created was pretty
> straightforward and I had a great time writing it in cake but my
> database skills aren't up to par with my php! Here goes:
>
> I have three tables that contain data which I want to relate,
> profiles, categories and topics. I created a categories_topics table
> with category_id and topic_id and that's just fine.
>
> However, I want to link the categories and topics to profiles so I
> created categories_topics_profiles which contains the
> category_topic_id (from the join table) and the profile_id (to link to
> the Profiles model) but it's giving me errors when I try to run a
> simple find.
>
> Is this the right way to build the tables or am I missing something?
> Any help would be GREATLY appreciated.
>
> Thanks,
> -Chris
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Database / Relationship question (habtm)

2009-07-21 Thread ulterior

I'm somewhat new to cake, this is my second app and I'm having
problems with relationships. The first app I created was pretty
straightforward and I had a great time writing it in cake but my
database skills aren't up to par with my php! Here goes:

I have three tables that contain data which I want to relate,
profiles, categories and topics. I created a categories_topics table
with category_id and topic_id and that's just fine.

However, I want to link the categories and topics to profiles so I
created categories_topics_profiles which contains the
category_topic_id (from the join table) and the profile_id (to link to
the Profiles model) but it's giving me errors when I try to run a
simple find.

Is this the right way to build the tables or am I missing something?
Any help would be GREATLY appreciated.

Thanks,
-Chris

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---