Message.cfc
component persistent="true" {
property name="messageId" ormtype="integer" fieldtype="id"
generator="increment";
property name="name" type="string";
property name="subject" type="string";
property name="body" ormtype="clob";
property name="isSent" type="boolean" ormtype="integer";
property name="isDeleted" type="boolean" ormtype="integer";
property name="dateCreated" ormtype="timestamp";
property name="lastUpdated" ormtype="timestamp";
property name="role" fieldtype="many-to-one" cfc="Role"
fkcolumn="roleid";
property name="dealer" fieldtype="many-to-one" cfc="Dealer"
fkcolumn="dealerid";
}
Dealer.cfc
component persistent="true" {
property name="dealerid" type="numeric" fieldtype="id"
generator="increment";
property name="name" type="string";
property name="account" type="numeric";
property name="email" type="string";
property name="isDeleted" type="boolean";
property name="dateCreated" ormtype="timestamp";
property name="lastUpdated" ormtype="timestamp";
property name="messages" fieldtype="one-to-many" cfc="Message"
fkcolumn="dealerid" singularname="message";
}
So its my understanding that I need to define what side of the
relationship will be in control. Since we will always be adding a
dealer to message the message should be in control of the
relationship.
property name="dealer" fieldtype="many-to-one" cfc="Dealer"
fkcolumn="dealerid" cascade="all" inverse="true";
I am having an issue with the save method. Lets say we chose a dealer
for this message to go to, but before we sent it we needed to change
it to a different dealer. How do you remove the old one, I thought we
could just do this.
var _message = variables.messageService.load(rc.id);
var _dealer = _message.getDealer();
_message.removeDealer(_dealer);
But the remove dealer method was not found? What am I doing wrong
here? I think I misunderstand the use of inverse even after reading a
number of articles.
So, doesn't work with "many-to-one" side like you're doing?
- Gabriel
> --
> You received this message because you are subscribed to the Google Groups "cf-orm-dev" group.
> To post to this group, send email to cf-or...@googlegroups.com.
> To unsubscribe from this group, send email to cf-orm-dev+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/cf-orm-dev?hl=en.
>
>
Just brainstorming so could be off base.
- Gabriel
On Mar 8, 2:59 pm, Dorioo <dor...@gmail.com> wrote:
> So maybe your relationship is many-to-many? Where a message can have
> many dealers (since you're trying to remove one and place another)
> but, in practice, only one dealer would be set on the message.
>
> Just brainstorming so could be off base.
>
> - Gabriel
>
>
>
> On Mon, Mar 8, 2010 at 2:53 PM, Dorioo <dor...@gmail.com> wrote:
> > Remove: "This method is generated for one-to-many and many-to-many
> > relationships."
>
> > So, doesn't work with "many-to-one" side like you're doing?
>
> > - Gabriel
>
- Gabriel
- Gabriel
The removeDealer-style methods are only available on collections, and
Message doesn't have a collection of Dealers, it has zero or one. So
you WOULD have Dealer.removeMessage available to you, since Dealer has
a collection of Messages.
It's also important to remember that you must deal with both ends of
the relationship. With a database, the foreign key is the single
bridge between the entities, but in the JVM there are a pair of
references (Message.dealer, and an item in Dealer.messages). BOTH
need to be severed if you truly want it to be severed. That has
nothing to do with Hibernate (or even Java), just standard reference
semantics. The gotcha is that depending on how you've mapped your
relationships to the DB, Hibernate may end up doing the right thing
even if you only sever one of the references when you next load the
entities. But for the remainder of the current session, your entities
are going to be inconsistent if you don't take care to sever both
ends.
Typically the way you manage this is via wrapper methods, so you'd
never manipulate the properties directly, but instead have a wrapper
that you use which ensures that both sides are severed:
function clearDealer() {
getDealer().removeMessage(this);
setDealer(javaCast('null', 0));
}
This is REALLY important, and typically forgotten, because most of the
time it happens to work correctly by coincidence. Not keeping it in
mind, however, can create some horribly subtle bugs.
cheers,
barneyb
--
Barney Boisvert
bboi...@gmail.com
http://www.barneyb.com/
You are correct, you can send a message to only one dealer at a time.
So if I am working on a message I should take this approach?
var _message = variables.messageService.load(rc.id);
var _dealer = _message.getDealer();
_dealer.removeMessage( _message );
I am not even sure that will work I just threw it together but is that
the idea? Seems kind of backwards to me. I like the idea of setting
the dealer to null, i might try that route.
cheers,
barneyb
--
--