Welcome Guest, Not a member yet? Register   Sign In
DMZ 1.7.1 (DataMapper OverZealous Edition)

[eluser]Atas[/eluser]
Hello, i have a question about Self Relationships.

Can i do the following instead of create a new dedicated table?.

One platform only can be associated to one platform.

CREATE TABLE `platform` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(255) default NULL,
`name_url` varchar(255) default NULL,
`platform_id`int(11) default NULL, /* HERE GOES THE PARENT PLATFORM ID */
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=latin1;


Thank you !

[eluser]introvert[/eluser]
[quote author="introvert" date="1279076097"][quote author="OverZealous" date="1279073654"]@introvert
If you'd read the docs, you'd see that check_last_query, by default, renders to the browser automatically. If you are also echoing it, you'll get the same output twice.

Obviously that would cause a database error if it tried to execute that.[/quote]

I don't get any error if I execute it with phpmyadmin 3.2.4. (MySQL client version: 5.1.37)
Can you please tell me which error do you get?
Do you maybe have any idea how I should restructure it to make it work? I have no idea what is going wrong.

Thanks a lot.[/quote]

I found out what the problem was.

The updated column seems to have a different timezone - the time has 2 hours difference if I compare it to NOW() which I call from mysql phpmyadmin.

Which setting should I set to fix that?

Use local_time or unix_time_stamp?

Thanks in advance.

[eluser]Tom Vogt[/eluser]
[quote author="Atas" date="1279131548"]Can i do the following instead of create a new dedicated table?. [/quote]

Yes, you can.

See http://www.overzealous.com/dmz/:
Quote:Some of the enhancements to the original DataMapper include:

* In-table foreign-keys for singular relationships.
(...)

[eluser]Atas[/eluser]
Hello,

@Tom Vogt
I am speaking about self relationship. I am reading this:

http://www.overzealous.com/dmz/pages/adv...tions.html [Self Relationships]

I don't want to use a dedicated table to do the relationship. I have a one-to-one self relationship.

Is this possible ?

Thankss!!

[eluser]Tom Vogt[/eluser]
[quote author="Atas" date="1279132663"]
I am speaking about self relationship. I am reading this:[/quote]

untested, but from what I've understood, this should work:
Code:
var $has_one = array('other'=>array('class'=>'myclass', 'other_field'=>'other'));

[eluser]Atas[/eluser]
Thanks!, it worked.

I did what you said.

Model Platform

Code:
class Platform extends DataMapper {
   var $table   = 'platform';
   var $has_one = array(
                      'platform'=>array(
                              'class'=>'platform',
                              'other_field'=>'platform'
                           )
                       );
   var $has_many = array('game');

   function __construct($id = NULL){
        parent::__construct($id);
   }
}

Table:

CREATE TABLE `platform` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(255) default NULL,
`name_url` varchar(255) default NULL,
`platform_id` int(11) default NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=latin1;


Sorry my english !

[eluser]introvert[/eluser]
Hi.

Is there any way to process/overwrite the certain object variable when its retrived?

For instance:

I have a model Product which has a variable price
After I preform get() I'd like to return $product->price with string "$product->price" . '€' (or $ if its in dollars)

Which is the best option to do that?
I dont want to call process_price() on each Product instance to return price with the currency symbol.

Thanks a lot for help!

[eluser]dejavu[/eluser]
I want to enrich some tables of standard code bases with more data. Instead of modifying the tables or changing the code, I'd like to do an inner join on the table's id, so I preserve the original table but add a few features.

So for example, let's say Drupal has a user table with
uid
name
email
login
pass


I'd like to have my DMZ table show
id
phone
notes
drupal_userid


Then using an inner join, I'd like to have these fields in my DataMapper object:
id
name
email

phone
notes

login
pass


I figure I can override methods (get, save_as_new, save, etc.) in DataMapper, but I want to minimize how much I touch the code. Any suggestions on how to do this gracefully?

Thanks.

[eluser]OverZealous[/eluser]
@introvert
See Get Rules. There's an entire section in the manual for just this behavior.

[eluser]The Hamburgler[/eluser]
I've been working some more with DMZ select_func() method and came across this problem. Could be a bug, could be just me do'in it wrong!

Query to select contacts grouped by first letter of their last_name

Code:
$contact->select_func('SUBSTRING', '@last_name, 1, 1', 'letter')->group_by('letter')->get();

Causes a mysql syntax error as the comma is inside the field name quotes

Code:
SELECT SUBSTRING(`contacts`.`last_name,` 1, 1) AS letter FROM (`contacts`) GROUP BY `letter`



Passing substring args as an array dosnt work either

Code:
$contact->select_func('SUBSTRING', array('@last_name', 1, 1), 'letter')->group_by('letter')->get()

Causes a mysql syntax error as there are no commas separating function arguments

Code:
SELECT SUBSTRING(`contacts`.`last_name` 1 1) AS letter FROM (`contacts`) GROUP BY `letter`



I found a way around this, by adding a space in-between the field name and the preceding comma.

Code:
$contact->select_func('SUBSTRING', '@last_name , 1, 1', 'letter')->group_by('letter')->get();

Thanks




Theme © iAndrew 2016 - Forum software by © MyBB