
Model scoping isn't considered for relations
Reported by Dirkjan Bussink | June 12th, 2009 @ 04:58 AM | in 0.10.0
The following script shows the issues which arises with for example using paranoia:
require 'rubygems'
require 'lib/dm-core'
class Person
include DataMapper::Resource property :id, Serial property
:deleted_at, ParanoidDateTime has n, :addresses end
class Address
include DataMapper::Resource property :id, Serial property
:deleted_at, ParanoidDateTime property :person_id, Integer
belongs_to :person end
DataMapper.setup(:default, 'sqlite3::memory:')
DataObjects::Sqlite3.logger = DataObjects::Logger.new('dm.log',
0)
DataMapper.auto_migrate!
Person.create
p Person.first.addresses
This results in the following SQL being executed:
Fri, 12 Jun 2009 09:57:01 GMT ~ debug ~ (0.000135) SELECT
sqlite_version(*)
Fri, 12 Jun 2009 09:57:01 GMT ~ debug ~ (0.000146) DROP TABLE IF
EXISTS "people"
Fri, 12 Jun 2009 09:57:01 GMT ~ debug ~ (0.000017) DROP TABLE IF
EXISTS "addresses"
Fri, 12 Jun 2009 09:57:01 GMT ~ debug ~ (0.000027) PRAGMA
table_info("people")
Fri, 12 Jun 2009 09:57:01 GMT ~ debug ~ (0.000413) CREATE TABLE
"people" ("id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"deleted_at" TIMESTAMP)
Fri, 12 Jun 2009 09:57:01 GMT ~ debug ~ (0.000010) PRAGMA
table_info("addresses")
Fri, 12 Jun 2009 09:57:01 GMT ~ debug ~ (0.000120) CREATE TABLE
"addresses" ("id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"deleted_at" TIMESTAMP, "person_id" INTEGER)
Fri, 12 Jun 2009 09:57:01 GMT ~ debug ~ (0.000063) INSERT INTO
"people" ("deleted_at") VALUES (NULL)
Fri, 12 Jun 2009 09:57:01 GMT ~ debug ~ (0.000044) SELECT "id" FROM
"people" WHERE "deleted_at" IS NULL ORDER BY "id" LIMIT 1
Fri, 12 Jun 2009 09:57:01 GMT ~ debug ~ (0.000041) SELECT "id",
"person_id" FROM "addresses" WHERE "person_id" = 1 ORDER BY
"id"
The initial person is correctly checked for deleted_at, but this doesn't happen when the addresses are loaded.
Comments and changes to this ticket
-
Dirkjan Bussink June 12th, 2009 @ 04:59 AM
require 'rubygems' require 'lib/dm-core' class Person include DataMapper::Resource property :id, Serial property :deleted_at, ParanoidDateTime has n, :addresses end class Address include DataMapper::Resource property :id, Serial property :deleted_at, ParanoidDateTime property :person_id, Integer belongs_to :person end DataMapper.setup(:default, 'sqlite3::memory:') DataObjects::Sqlite3.logger = DataObjects::Logger.new('dm.log', 0) DataMapper.auto_migrate! Person.create p Person.first.addresses
-
Dirkjan Bussink June 12th, 2009 @ 04:59 AM
Fri, 12 Jun 2009 09:57:01 GMT ~ debug ~ (0.000135) SELECT sqlite_version(*) Fri, 12 Jun 2009 09:57:01 GMT ~ debug ~ (0.000146) DROP TABLE IF EXISTS "people" Fri, 12 Jun 2009 09:57:01 GMT ~ debug ~ (0.000017) DROP TABLE IF EXISTS "addresses" Fri, 12 Jun 2009 09:57:01 GMT ~ debug ~ (0.000027) PRAGMA table_info("people") Fri, 12 Jun 2009 09:57:01 GMT ~ debug ~ (0.000413) CREATE TABLE "people" ("id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, "deleted_at" TIMESTAMP) Fri, 12 Jun 2009 09:57:01 GMT ~ debug ~ (0.000010) PRAGMA table_info("addresses") Fri, 12 Jun 2009 09:57:01 GMT ~ debug ~ (0.000120) CREATE TABLE "addresses" ("id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, "deleted_at" TIMESTAMP, "person_id" INTEGER) Fri, 12 Jun 2009 09:57:01 GMT ~ debug ~ (0.000063) INSERT INTO "people" ("deleted_at") VALUES (NULL) Fri, 12 Jun 2009 09:57:01 GMT ~ debug ~ (0.000044) SELECT "id" FROM "people" WHERE "deleted_at" IS NULL ORDER BY "id" LIMIT 1 Fri, 12 Jun 2009 09:57:01 GMT ~ debug ~ (0.000041) SELECT "id", "person_id" FROM "addresses" WHERE "person_id" = 1 ORDER BY "id"
-
Dan Kubb (dkubb) June 15th, 2009 @ 10:42 PM
- State changed from unconfirmed to accepted
-
Dan Kubb (dkubb) June 12th, 2009 @ 04:58 AM
- State changed from accepted to resolved
(from [e7e2e418bf3bb5ad09d0767f6183e1f69048063e]) Update Relationship#query_for to respect target model scope
[#897 state:resolved] http://github.com/datamapper/dm-core/commit/e7e2e418bf3bb5ad09d0767...
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
People watching this ticket
Tags
Referenced by
-
897 Model scoping isn't considered for relations [#897 state:resolved] http://github.com/datamapper/dm-co...